Skip to content

Mutex.unlock with Unconfined dispatcher causes StackOverflowError #80

Closed
@wetnose

Description

@wetnose

Just run the following example and look at the result

fun main(args: Array<String>) {

    val waiters = 1000

    val mutex = Mutex()
    val start = CountDownLatch(1)
    val done  = CountDownLatch(waiters)

    launch(CommonPool) {
        mutex.lock()
        try {
            start.await()
        } finally {
            mutex.unlock() // StackOverflowError
        }
    }

    repeat(waiters) {
        launch(Unconfined) {
            mutex.withLock {
                done.countDown()
            }
        }
    }

    start.countDown()
    println(done.await(1, SECONDS))
}

Could you avoid using call stack when iterating lock waiters?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions