Skip to content

EventLoop integration and reuse for runBlocking and Unconfined dispatchers #889

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

Merged
merged 9 commits into from
Dec 21, 2018

Conversation

elizarov
Copy link
Contributor

  • Event loop that is created by runBlocking or by Unconfined dispatcher
    is reused across the same thread to prevent blocking of the loop
  • Semantics of runBlocking and Unconfined are fully retained
  • DefaultExecutor also registers itself as running event loop and thus
    cannot be blocked by runBlocking
  • Consolidates thread-local handling for native
  • Also fixes thread-local memory leak on JVM (does not use custom class)

Fixes #860

@elizarov elizarov requested a review from qwwdfsad December 13, 2018 21:29
@elizarov elizarov force-pushed the event-loops branch 3 times, most recently from 11a90d7 to b91442a Compare December 13, 2018 21:55
…chers

- Event loop that is created by runBlocking or by Unconfined dispatcher
  is reused across the same thread to prevent blocking of the loop
- Semantics of runBlocking and Unconfined are fully retained
- DefaultExecutor also registers itself as running event loop and thus
  cannot be blocked by runBlocking
- Consolidates thread-local handling for native
- Also fixes thread-local memory leak on JVM (does not use custom class)

Fixes #860
It is a name people are used to seen then they example the coroutineContext
inside runBlocking. The fact that it is also used for unconfined now
is Ok as it is not directly exposed.
To be used by kotlinx-io
* Unused ArrayQueue is dropped
* executeUnconfined and resumeUnconfined are defined as extension funs
* EventLoop.increment renamed to delta
* Test for EventLoop added

Note: This PR also fixes #850
…oop)

Previous logic of handling runBlocking(context) had a flaw in that the
presence of EventLoop-capable dispatcher in the context lead to the
blocking of current thread's event loop. Test for this issue is added.
Must be invoked from the correct thread.
So that runBlocking processes events from TestCoroutineContext
* Unconfined tasks take priority over others
* Tracking of unconfined tasks simplified
* Removed duplication between ArrayQueue/Queue classes in JS
@qwwdfsad qwwdfsad merged commit 5173824 into develop Dec 21, 2018
@qwwdfsad qwwdfsad deleted the event-loops branch December 21, 2018 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants