override fun waitOnMonitor()

in src/jvm/main/org/jetbrains/kotlinx/lincheck/strategy/managed/modelchecking/ModelCheckingStrategy.kt [596:621]


    override fun waitOnMonitor(threadId: Int, monitor: Any): Boolean {
        // TODO: we can add spurious wake-ups here
        var info = acquiredMonitors[monitor]
        if (info != null) {
            // in case when the lock is currently acquired by another thread, continue waiting
            if (info.threadId != threadId) return true
            // in case when current thread owns the lock we release it
            // to give other threads a chance to acquire it,
            // and we put the current thread into the waiting state
            info.waitForNotify = true
            waitingMonitor[threadId] = info
            acquiredMonitors.remove(monitor)
            return true
        }
        // otherwise the lock is held by no-one and can be acquired
        info = waitingMonitor[threadId]
        check(info != null && info.monitor === monitor && info.threadId == threadId) {
            "Monitor should have been acquired by this thread"
        }
        // if there has been no `notify` yet continue waiting
        if (info.waitForNotify) return true
        // otherwise acquire monitor restoring its re-entrance depth
        acquiredMonitors[monitor] = info
        waitingMonitor[threadId] = null
        return false
    }