https://kotlinlang.org logo
Title
g

groostav

03/03/2019, 7:39 PM
I'm trying to get a good grip on the result using
Unconfined
to try and keep stacks neat. Namely I'd like to use an unconfined consumer to keep the producer on the stack trace, But I think there's a races making my life hard. AFAIK the contract with unconfined is so weak (and is aimed at performance, not debugability) that perhaps this isn't a bug per se, but Id still like to see it. Proof-of-concept: https://gist.github.com/Groostav/f8ef01ed830c14c394ac5b992d981aa1 if you put a breakpoint on
send
and walk-through the the downstack implementation it will eventually invoke the receiver
, If you just run the test, on my machine, the
runBlocking
event loop will invoke the receiver.
v

Vsevolod Tolstopyatov [JB]

03/04/2019, 10:01 AM
It is because you have a race in your code. Callstack depends on whether
send
completes before line with
GlobalScope.launch(Dispatchers.Unconfined)
is executed or after. Moreover, during nested unconfined calls,
kx.coroutines
does some magic and unrolls the stack in order to avoid possible stack overflows
🤔 1
If you really need readable stacktraces, I encourage you to enable debug mode (https://github.com/Kotlin/kotlinx.coroutines/blob/develop/docs/debugging.md) and report if some pattern does not work when it should
✔️ 1
g

groostav

03/04/2019, 7:14 PM
@Vsevolod Tolstopyatov [JB] I dont suppose this stands a chance of becoming a
CoroutineContext
element, such that I could specify some tree of coroutines has this enabled in production? I want this because the majority of my coroutines, including javafx click handlers and this library I'm working on simply aren't performance sensitive, and would stand to gain a lot if the stack trace included the
bubbling click event
as the ultimate "caused by" rather than an opaque
Platform.runLater
kicked off by some resume method