https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

Daniele Segato

09/28/2020, 9:05 AM
This question is out of curiousity, I do not currently need this. Is there a reentrant lock (mutex) for kotlin coroutines? If not why? Couldn't the context / parent context act as the reentrant discriminant? (if a parent scope hold the lock a children can enter it) Previous question (which basically explain what a reentrant lock is): Is there something in coroutines that works as a context-aware mutex in a way similar to
synchronize
keyword? Synchronize lock access to the thread level. This means that if you call another fun that use the synchronize on the same object without jumping threads that fun doesn't block at the synchronize keyword. With coroutines if you use a mutex in 2 fun and one call the other it creates a deadlock. Is there something like a mutex that allow "children" coroutines of the lock holder go into the lock?
w

wasyl

09/28/2020, 9:09 AM
So you’re looking for a reentrant Mutex? Javadoc for Mutex says explicitly it’s non-reentrant but it doesn’t suggest an alternative, and seems like there isn’t one: https://github.com/Kotlin/kotlinx.coroutines/issues/1686 (also https://github.com/Kotlin/kotlinx.coroutines/issues/965)
d

Daniele Segato

09/28/2020, 9:17 AM
yes exactly, but instead of just saying reentrant I went ahead and tried to explain it with my words 😛
👍 1
2 Views