Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions tests/vulpix-tests/unit/deadlock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ object Test {
val lock1 = new Lock
val lock2 = new Lock

private[this] var took1: Boolean = false
private[this] var took2: Boolean = false
def lock2Taken(): Unit = synchronized {
took2 = true
notify()
}
def tookLock2: Boolean = synchronized(took2)

val thread1 = new Thread {
override def run(): Unit = synchronized {
override def run(): Unit = {
lock1.synchronized {
while (!tookLock2) wait()
took1 = true
while (!took2) Thread.sleep(100)
lock2.synchronized {
println("thread1 in lock2!")
}
Expand All @@ -23,9 +20,10 @@ object Test {
}

val thread2 = new Thread {
override def run(): Unit = synchronized {
override def run(): Unit = {
lock2.synchronized {
lock2Taken()
took2 = true
while (!took1) Thread.sleep(100)
lock1.synchronized {
println("thread2 in lock1!")
}
Expand Down