From 8efd7f032249b3d4a44797a258614d1324685de1 Mon Sep 17 00:00:00 2001 From: Celia_Wu <530081999@qq.com> Date: Thu, 1 Aug 2019 23:45:04 +0800 Subject: [PATCH] 2019-08-01 --- ...\233\277\346\211\223\345\215\260FooBar.py" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "1115.\344\272\244\346\233\277\346\211\223\345\215\260FooBar/1115-\344\272\244\346\233\277\346\211\223\345\215\260FooBar.py" diff --git "a/1115.\344\272\244\346\233\277\346\211\223\345\215\260FooBar/1115-\344\272\244\346\233\277\346\211\223\345\215\260FooBar.py" "b/1115.\344\272\244\346\233\277\346\211\223\345\215\260FooBar/1115-\344\272\244\346\233\277\346\211\223\345\215\260FooBar.py" new file mode 100644 index 0000000..87c83c7 --- /dev/null +++ "b/1115.\344\272\244\346\233\277\346\211\223\345\215\260FooBar/1115-\344\272\244\346\233\277\346\211\223\345\215\260FooBar.py" @@ -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() + + \ No newline at end of file