Skip to content

Commit 45af82c

Browse files
authored
Merge pull request #6006 from dotty-staging/fix-deadlock
Fix deadlock meta test
2 parents 21a2cd8 + 6b12f36 commit 45af82c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

tests/vulpix-tests/unit/deadlock.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ object Test {
33
val lock1 = new Lock
44
val lock2 = new Lock
55

6+
private[this] var took1: Boolean = false
67
private[this] var took2: Boolean = false
7-
def lock2Taken(): Unit = synchronized {
8-
took2 = true
9-
notify()
10-
}
11-
def tookLock2: Boolean = synchronized(took2)
128

139
val thread1 = new Thread {
14-
override def run(): Unit = synchronized {
10+
override def run(): Unit = {
1511
lock1.synchronized {
16-
while (!tookLock2) wait()
12+
took1 = true
13+
while (!took2) Thread.sleep(100)
1714
lock2.synchronized {
1815
println("thread1 in lock2!")
1916
}
@@ -23,9 +20,10 @@ object Test {
2320
}
2421

2522
val thread2 = new Thread {
26-
override def run(): Unit = synchronized {
23+
override def run(): Unit = {
2724
lock2.synchronized {
28-
lock2Taken()
25+
took2 = true
26+
while (!took1) Thread.sleep(100)
2927
lock1.synchronized {
3028
println("thread2 in lock1!")
3129
}

0 commit comments

Comments
 (0)