-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (23 loc) · 864 Bytes
/
Copy pathmain.py
File metadata and controls
36 lines (23 loc) · 864 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
#----------------------------- this is the driver program--------------------------#
import Fast #needed so can invoke the Fast algorithm
import Bakery #needed so can invoke the Bakery algorithm
import random
import sys
if len(sys.argv)!=3:
sys.exit("\n\nwrong number of arguments, usage: python randnum.py threads requests\n\n")
thr = int(sys.argv[1])
req = int(sys.argv[2])
#initialising a list whose index represents the thread and its value the number requests assigned to it
assign = [0]*thr
# randomly distributing the requests among the threads
while req:
j = random.randrange(0, thr)
assign[j]+=1
req-=1
# just to check
for x in assign:
print (x)
print ("\nRunning Lamport's fast mutual exclusion algorithm\n")
Fast.spawnThreads(assign)
print ("\n\nRunning Lamport's bakery algorithm\n\n")
Bakery.spawnThreads(assign)