Skip to content

Instantly share code, notes, and snippets.

@mr-yoo
Created May 1, 2021 05:42
Show Gist options
  • Save mr-yoo/51909c3fb67579aa673527c46a373c20 to your computer and use it in GitHub Desktop.
Save mr-yoo/51909c3fb67579aa673527c46a373c20 to your computer and use it in GitHub Desktop.
쓰레드 동기화 문제
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