File tree 1 file changed +19
-1
lines changed
1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Included IntelliJ-related patches
2
- - TODO
2
+
3
+ ## ` runBlocking ` without Dispatcher starvation
4
+
5
+ [ IJPL-721] ( https://youtrack.jetbrains.com/issue/IJPL-721 ) , [ #3983 ] ( https://github.com/Kotlin/kotlinx.coroutines/issues/3983 )
6
+
7
+ ### Description:
8
+ ` runBlocking ` with its default semantics may cause dispatcher starvation if it is called on a worker thread.
9
+ For example, if ` runBlocking ` happens to block all ` Dispatchers.Default ` workers, it may lead to a deadlock in the application:
10
+ there may be tasks in the CPU queue that ` runBlocking ` s await, but there are none CPU workers available to run them.
11
+
12
+ This patch changes the behavior of ` runBlocking ` so that it always releases associated computation permits before it parks,
13
+ and reacquires them after unpark. It works for every ` CoroutineDispatcher ` that is built using library primitives:
14
+ plain ` Dispatcher.* ` objects or ` .limitedParallelism ` limited dispatchers that are on top of them.
15
+
16
+ This change in behavior comes with a cost. Permit reacquiring mechanism _ may_ need an additional thread park/unpark.
17
+ Worker threads that release their computational permits always let go of the local task queue, which means less benefit
18
+ from locality, higher contention and transactional costs at the very least.
19
+
20
+ This patch doesn't change the fact that ` runBlocking ` should still be used carefully.
You can’t perform that action at this time.
0 commit comments