-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path1114.printInOrder.cpp
More file actions
34 lines (26 loc) · 834 Bytes
/
1114.printInOrder.cpp
File metadata and controls
34 lines (26 loc) · 834 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
class Foo {
public int lockF = 0;
public int lockS = 0;
public Foo() {
}
public void first(Runnable printFirst) throws InterruptedException {
// printFirst.run() outputs "first". Do not change or remove this line.
printFirst.run();
lockF = 1;
}
public void second(Runnable printSecond) throws InterruptedException {
// printSecond.run() outputs "second". Do not change or remove this line.
while(lockF == 0) {
}
printSecond.run();
lockS = 1;
}
public void third(Runnable printThird) throws InterruptedException {
// printThird.run() outputs "third". Do not change or remove this line.
while(lockF == 0) {
}
while(lockS == 0) {
}
printThird.run();
}
}