




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





54
55
int cnt = 0; t1.run() { synchronized(lock) { int y = cnt; cnt = y + 1; } } t2.run() { synchronized(lock) { int y = cnt; cnt = y + 1; } }
56
int cnt = 0; t1.run() { synchronized(lock) { int y = cnt; cnt = y + 1; } } t2.run() { synchronized(lock) { int y = cnt; cnt = y + 1; } }
57
int cnt = 0; t1.run() { synchronized(lock) { int y = cnt; cnt = y + 1; } } t2.run() { synchronized(lock) { int y = cnt; cnt = y + 1; } }
58
int cnt = 0; t1.run() { synchronized(lock) { int y = cnt; cnt = y + 1; } } t2.run() { synchronized(lock) { int y = cnt; cnt = y + 1; } }
59
int cnt = 0; t1.run() { synchronized(lock) { int y = cnt; cnt = y + 1; } } t2.run() { synchronized(lock) { int y = cnt; cnt = y + 1; } }
60
int cnt = 0; t1.run() { synchronized(lock) { int y = cnt; cnt = y + 1; } } t2.run() { synchronized(lock) { int y = cnt; cnt = y + 1; } }
65
66
public class State { private int cnt = 0; public int synchronized incCnt(int x) { cnt += x; } public int synchronized getCnt() { return cnt; } } public class MyThread extends Thread { State s; public MyThread(State s) { this.s = s; } public void run() { s.incCnt(1) } public void main(String args[]) { State s = new State(); MyThread thread1 = new MyThread(s); MyThread thread2 = new MyThread(s); thread1.start(); thread2.start(); } }
67
68
Object A = new Object(); Object B = new Object(); T1.run() { synchronized (A) { synchronized (B) { … } } }
T2.run() { synchronized (B) { synchronized (A) { … } } }
69
70
71
72
77
78
This document was created with Win2PDF available at http://www.daneprairie.com.
The unregistered version of Win2PDF is for evaluation or non-commercial use only.