Created
October 21, 2023 18:22
-
-
Save orcchg/8b4bb6254c13888ad7e16f75f68f2294 to your computer and use it in GitHub Desktop.
Next coroutine suspends at the very beginning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suspend fun <T> synchronized(block: suspend () -> T): T { | |
val thisJobId = id.getAndIncrement() | |
while (isInsideCriticalSection) { | |
suspendCoroutine { cont -> // <-- suspending call | |
suspendedJobs[thisJobId] = cont | |
} | |
suspendedJobs.remove(thisJobId) | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment