File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -3,17 +3,14 @@ object Test {
3
3
val lock1 = new Lock
4
4
val lock2 = new Lock
5
5
6
+ private [this ] var took1 : Boolean = false
6
7
private [this ] var took2 : Boolean = false
7
- def lock2Taken (): Unit = synchronized {
8
- took2 = true
9
- notify()
10
- }
11
- def tookLock2 : Boolean = synchronized (took2)
12
8
13
9
val thread1 = new Thread {
14
- override def run (): Unit = synchronized {
10
+ override def run (): Unit = {
15
11
lock1.synchronized {
16
- while (! tookLock2) wait()
12
+ took1 = true
13
+ while (! took2) Thread .sleep(100 )
17
14
lock2.synchronized {
18
15
println(" thread1 in lock2!" )
19
16
}
@@ -23,9 +20,10 @@ object Test {
23
20
}
24
21
25
22
val thread2 = new Thread {
26
- override def run (): Unit = synchronized {
23
+ override def run (): Unit = {
27
24
lock2.synchronized {
28
- lock2Taken()
25
+ took2 = true
26
+ while (! took1) Thread .sleep(100 )
29
27
lock1.synchronized {
30
28
println(" thread2 in lock1!" )
31
29
}
You can’t perform that action at this time.
0 commit comments