첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
import threading
import time

count = 10
lock  = threading.Lock()

class Developer(threading.Thread):
    def __init__(self, name):
        threading.Thread.__init__(self)
        self.name  = name
        self.fixed = 0

    def run(self):
        global count
        while True:
            lock.acquire()
            if count > 0:
                count -= 1
                lock.release()
                self.fixed += 1
                time.sleep(0.1)
            else:
                lock.release()
                break

developerList = []

for name in ["스레드1", "스레드2", "스레드3"]:
    devloper = Developer(name)
    developerList.append(devloper)
    devloper.start()

for devloper in developerList:
    devloper.join()
    print(devloper.name, "fixed", devloper.fixed)

"""
스레드1 fixed 3
스레드2 fixed 4
스레드3 fixed 3
"""
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요