Skip to content

Instantly share code, notes, and snippets.

@toandaominh1997
Last active September 20, 2020 02:33
Show Gist options
  • Save toandaominh1997/f335a6c44d70a1559231da766d920018 to your computer and use it in GitHub Desktop.
Save toandaominh1997/f335a6c44d70a1559231da766d920018 to your computer and use it in GitHub Desktop.
test github cli
import threading
x = 0
def increament(): global x x +=1
def thread_task(lock): for _ in range(100000):
lock.acquire() increament() lock.release()
def main_task(): global x x = 0 lock = threading.Lock() t1 = threading.Thread(target=thread_task, args=(lock, )) t2 = threading.Thread(target=thread_task, args=(lock, )) t3 =
threading.Thread(target=thread_task, args=(lock, ))
t1.start() t2.start() t3.start()
t1.join() t2.join() t3.join()
if __name__=='__main__': for i in range(10):
main_task() print('Iterator {}: x = {}'.format(i, x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment