Skip to content

Commit

Permalink
2019-08-01
Browse files Browse the repository at this point in the history
  • Loading branch information
JiayangWu committed Aug 1, 2019
1 parent ba0a62a commit 8efd7f0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions 1115.交替打印FooBar/1115-交替打印FooBar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from threading import *
class FooBar(object):
def __init__(self, n):
self.n = n
self.lock_foo = Semaphore()
self.lock_foo.acquire()
self.lock_bar = Semaphore()
self.lock_bar.acquire()

def foo(self, printFoo):
"""
:type printFoo: method
:rtype: void
"""
for i in xrange(self.n):
# printFoo() outputs "foo". Do not change or remove this line.

printFoo()
self.lock_bar.release()
self.lock_foo.acquire()


def bar(self, printBar):
"""
:type printBar: method
:rtype: void
"""
for i in xrange(self.n):
# printBar() outputs "bar". Do not change or remove this line.
self.lock_bar.acquire()
printBar()

self.lock_foo.release()


0 comments on commit 8efd7f0

Please sign in to comment.