-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast.py
More file actions
38 lines (27 loc) · 752 Bytes
/
Copy pathfast.py
File metadata and controls
38 lines (27 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import threading
import time
import logging
class peterson(threading.Thread):
counter = 10
logging.basicConfig(level=logging.DEBUG, format='[%(threadName)s, %(message)s]')
B = [0]*2
def __init__(self, threadName):
self.threadName = threadName
threading.Thread.__init__(self)
def run(self):
logging.debug('starting')
time.sleep(2)
while peterson.counter:
threadlock.acquire()
enterCS()
threadlock.release()
peterson.counter-=1
def enterCS():
logging.debug('now in cs...')
threadlock = threading.Lock()
p_1 = peterson('process 1')
p_2 = peterson('process 2')
p_1.start()
p_2.start()
while 1:
pass