I’m hoping to write an efficient read-write lock for coroutines.

There is an inefficient implementation given here: https://github.com/Kotlin/kotlinx.coroutines/issues/94

Initially, I was using as a starting point the official Mutex source: https://github.com/Kotlin/kotlinx.coroutines/blob/master/core/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/sync/Mutex.kt

But I was quickly overwhelmed. So I decided to go for a semi-efficient solution first, starting with the simplified Mutex example code here: https://github.com/Kotlin/kotlin-coroutines/blob/master/examples/mutex/mutex.kt

My question is about this simplified implementation. In particular, I don’t see how line 37 is reachable. There is only one place where the resumed field can be mutated: on line 38. Is there a missing line to set a waiter’s resumed field to true in the unlock() method? Or am I missing something?