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 {
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 }
You can’t perform that action at this time.
0 commit comments