import threading
class FooBar:
def __init__(self, n):
self.n = n
self.l1 = threading.Lock()
self.l2 = threading.Lock()
self.l2.acquire()
# self.l1.acquire()
def foo(self, printFoo: 'Callable[[], None]') -> None:
for i in range(self.n):
# printFoo() outputs "foo". Do not change or remove this line.
self.l1.acquire()
printFoo()
self.l2.release()
def bar(self, printBar: 'Callable[[], None]') -> None:
for i in range(self.n):
# printBar() outputs "bar". Do not change or remove this line.
self.l2.acquire()
printBar()
self.l1.release()
leetcode刷题python之交替打印FooBar
最新推荐文章于 2023-04-10 15:00:26 发布