Created
May 1, 2021 05:42
-
-
Save mr-yoo/51909c3fb67579aa673527c46a373c20 to your computer and use it in GitHub Desktop.
쓰레드 동기화 문제
This file contains hidden or 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 | |
# 전역 변수 | |
r = 0 | |
class Consumer(threading.Thread): | |
def run(self): | |
global r | |
for _ in range(1000000): | |
r += 1 | |
class Producer(threading.Thread): | |
def run(self): | |
global r | |
for _ in range(1000000): | |
r -= 1 | |
Producer().start() | |
Consumer().start() | |
print(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment