spand
09/25/2018, 12:17 PMsynchronized(lock){
implicitScope.launch {
delay(1)
}
}
I get an error that says: " The 'delay' suspension point is inside a critical section". Seems safe to me ?Vsevolod Tolstopyatov [JB]
09/25/2018, 12:33 PMIllegalMonitorException
spand
09/25/2018, 12:37 PMVsevolod Tolstopyatov [JB]
09/25/2018, 12:38 PMI dont expect the delay to take place on the initial thread.But
synchronized
machinery do, that’s why it is forbiddenspand
09/25/2018, 12:45 PMclass Foo : CoroutineScope by GlobalScope {
fun foo() = synchronized(Any()){
myLaunch()
}
fun myLaunch(): Job = launch {
delay(1)
}
}
but after inlining myLaunch
it is not. Why is it not just plain old normal blocking code?Vsevolod Tolstopyatov [JB]
09/25/2018, 12:52 PMmyLaunch
is not suspending function and does not suspend. It just launches new task with delay and this task will be executed outside of the syncrhonized
blockspand
09/25/2018, 1:02 PMlaunch
is not a suspending function either. Why does the block given to launch
have any relation to the synchronized here?launch
, hence I cant see why it is a problem.uhe
09/25/2018, 1:24 PMspand
09/25/2018, 1:26 PMVsevolod Tolstopyatov [JB]
09/25/2018, 1:37 PM