-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android: Main.immediate causes a dispatch using Unconfined inside #1650
Comments
By the way using
|
This is a protection to avoid spurious stack overflows when you have (usually implicit) nested unconfined coroutines. Otherwise, the simplest ping-pong with a channel and two unconfined coroutines would fail with This behaviour reflected both in
|
Well I didn't think that I think the documentation to
The part about "as if the coroutine was started using [Dispatchers.Unconfined]" seems false when we are dealing with nested unconfined coroutines. |
Good point, I will adjust our documentation accordingly |
Btw is there a way to force a non-dispatch in cases where it is known that no stack overflow can occur (I mean within reasonable limits). For example, if I have two coroutines but the data flows only one way. In that case dispatch is superfluous (and can create data races). Look at the following example:
I would like to force such statement execution order:
Instead I always get
|
It is a mix of "immediate" interaction with channel unfairness (#111).
No way to force this behaviour on the level of a dispatcher, because it's easy to make a mistake here e.g. during code evolution, not at the moment of writing, thus we don't endorse this. |
Dispatchers.Main.immediate
forces child coroutine withDispatchers.Unconfined
interceptor to dispatch.Example code
This code prints
But expected would be backwards.
I can force not to dispatch if I use
start = CoroutineStart.UNDISPATCHED
. Then I get the expected resultBut shouldn't
GlobalScope.launch(Dispatchers.Unconfined)
andGlobalScope.launch(start = CoroutineStart.UNDISPATCHED, context = Dispatchers.Unconfined)
be interchangable?The text was updated successfully, but these errors were encountered: