We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ba0a62a commit 8efd7f0Copy full SHA for 8efd7f0
1115.交替打印FooBar/1115-交替打印FooBar.py
@@ -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
21
22
23
+ def bar(self, printBar):
24
25
+ :type printBar: method
26
27
28
29
+ # printBar() outputs "bar". Do not change or remove this line.
30
31
+ printBar()
32
33
+ self.lock_foo.release()
34
35
0 commit comments