https://kotlinlang.org logo
Title
m

Marc Knaup

04/29/2020, 7:19 AM
Is there a way to debug
Mutex
deadlocks caused by recursion?
o

octylFractal

04/29/2020, 7:20 AM
there's the
owner
parameter, you can pass that and it will throw if you re-lock with the same
owner
m

Marc Knaup

04/29/2020, 7:21 AM
Yes, but that doesn’t help me with accidental recursion?
o

octylFractal

04/29/2020, 7:21 AM
depends on your choice of
owner
I guess
if you were to store an element in the coroutine context, it would still be there post-recursion, so you could initialize e.g.
coroutineContext[MyDebugElement] = coroutineContext[MyDebugElement] ?: Any()
, and then pass that as the
owner
. if you recurse, then you'll use the same unique object and it'll throw
m

Marc Knaup

04/29/2020, 7:41 AM
Hmm, it wouldn’t be inherited by lauched coroutines I presume?
o

octylFractal

04/29/2020, 7:42 AM
no, it wouldn't
l

louiscad

04/29/2020, 9:00 AM
It'd actually, unless it is replaced. That's how it works for all coroutineContext elements, like
ContinuationInterceptor
(
CoroutineDispatcher
implements it).
o

octylFractal

04/29/2020, 2:31 PM
oh, well I guess it depends on how you launch
if you do it in
coroutineScope {}
or similar then yes
but if you're legitimately switching to a new context via a separate scope, then no