This question is out of curiousity, I do not curre...
# coroutines
d
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
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
yes exactly, but instead of just saying reentrant I went ahead and tried to explain it with my words 😛
👍 1