Skip to content

Commit 8efd7f0

Browse files
committedAug 1, 2019
2019-08-01
1 parent ba0a62a commit 8efd7f0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from threading import *
2+
class FooBar(object):
3+
def __init__(self, n):
4+
self.n = n
5+
self.lock_foo = Semaphore()
6+
self.lock_foo.acquire()
7+
self.lock_bar = Semaphore()
8+
self.lock_bar.acquire()
9+
10+
def foo(self, printFoo):
11+
"""
12+
:type printFoo: method
13+
:rtype: void
14+
"""
15+
for i in xrange(self.n):
16+
# printFoo() outputs "foo". Do not change or remove this line.
17+
18+
printFoo()
19+
self.lock_bar.release()
20+
self.lock_foo.acquire()
21+
22+
23+
def bar(self, printBar):
24+
"""
25+
:type printBar: method
26+
:rtype: void
27+
"""
28+
for i in xrange(self.n):
29+
# printBar() outputs "bar". Do not change or remove this line.
30+
self.lock_bar.acquire()
31+
printBar()
32+
33+
self.lock_foo.release()
34+
35+

0 commit comments

Comments
 (0)