-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDekkerSimple.java
More file actions
43 lines (36 loc) · 886 Bytes
/
DekkerSimple.java
File metadata and controls
43 lines (36 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class P1 extends Thread{
private int t=1;
private int iIteraciones = 10;
public void run(){
while (iIteraciones > 0) {
t=1;
while(t != 1){}
//sc
System.out.println("Entro en SC de P1, con turno: "+ t);
t = 2;
iIteraciones--;
}
}
}
class P2 extends Thread{
private int t=2;
private int iIteraciones = 10;
public void run(){
while (iIteraciones > 0) {
t= 2;
while(t != 2){}
//SC
System.out.println("Entro en SC de P2, con turno: "+ t);
t=1;
iIteraciones--;
}
}
}
public class DekkerSimple {
public static void main (String args[]) throws Exception{
P2 p2 = new P2();
P1 p1 = new P1();
p1.start();p2.start();
p1.join();p2.join();
}
}