-
-
Save toandaominh1997/f335a6c44d70a1559231da766d920018 to your computer and use it in GitHub Desktop.
test github cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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