| 1 | import threading |
| 2 | import time |
| 3 | class MyThread(threading.Thread): |
| 4 | def run(self): |
| 5 | global num |
| 6 | time.sleep(5) |
| 7 | |
| 8 | if mutex.acquire(1): |
| 9 | |
| 10 | num +=1 |
| 11 | msg = self.name + 'set num to ' +str(num) |
| 12 | print(msg) |
| 13 | mutex.release() |
| 14 | num = 0 |
| 15 | mutex = threading.Lock() |
| 16 | def test(): |