-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1114-Print-in-Order.py
More file actions
29 lines (24 loc) · 944 Bytes
/
1114-Print-in-Order.py
File metadata and controls
29 lines (24 loc) · 944 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
import threading
class Foo:
def __init__(self):
self.cond1=threading.Condition()
self.cnt=1
def first(self, printFirst: 'Callable[[], None]') -> None:
with self.cond1:
# printFirst() outputs "first". Do not change or remove this line.
printFirst()
self.cnt+=1
self.cond1.notifyAll()
def second(self, printSecond: 'Callable[[], None]') -> None:
with self.cond1:
# printSecond() outputs "second". Do not change or remove this line.
self.cond1.wait_for(lambda:self.cnt==2)
printSecond()
self.cnt+=1
self.cond1.notifyAll()
def third(self, printThird: 'Callable[[], None]') -> None:
with self.cond1:
self.cond1.wait_for(lambda:self.cnt==3)
printThird()
# printThird() outputs "third". Do not change or remove this line.
# self.cond2.wait()