Update Concurrent Programming
This commit is contained in:
parent
fec95335a9
commit
53df6f852a
|
@ -9,22 +9,22 @@ local_threads_number = 10
|
|||
number_of_cycles = 20
|
||||
renew = []
|
||||
done = []
|
||||
space = []
|
||||
arrows = []
|
||||
copy = []
|
||||
|
||||
def init():
|
||||
for i in range(0, renew_length):
|
||||
renew.append(0)
|
||||
for j in range(0, local_threads_number):
|
||||
space.append(random.randint(10,99))
|
||||
copy.append(space[j])
|
||||
print(' ',space,' < initial global state',' '*27,end='[')
|
||||
arrows.append(random.randint(10,99))
|
||||
copy.append(arrows[j])
|
||||
print(' ',arrows,' < initial global state',' '*27,end='[')
|
||||
for i in range(0, renew_length): print('{:>4}'.format(renew[i]), end='')
|
||||
print(']')
|
||||
|
||||
def disp(coord, id, start, prev, next):
|
||||
print(' {} at [{}] {} > {} by thread n°{:>3} {!s:.4} {}'.format(
|
||||
space,
|
||||
arrows,
|
||||
coord,
|
||||
prev,
|
||||
next,
|
||||
|
@ -42,8 +42,8 @@ def local_thread(coord, id):
|
|||
start = datetime.now().timestamp()
|
||||
val = random.randint(1,1000)
|
||||
time.sleep(val / 1000)
|
||||
prev = space[coord]
|
||||
next = space[coord] = 10 + val % 89
|
||||
prev = arrows[coord]
|
||||
next = arrows[coord] = 10 + val % 89
|
||||
done.append(id)
|
||||
for i in range(0, renew_length):
|
||||
if renew[i] == id:
|
||||
|
@ -52,11 +52,14 @@ def local_thread(coord, id):
|
|||
disp(coord, id, start, prev, next)
|
||||
|
||||
init() # Scheduler
|
||||
for id in range (1, number_of_cycles):
|
||||
if renew[id % renew_length] == 0:
|
||||
renew[id % renew_length] = id
|
||||
|
||||
t = Thread(target=local_thread, args=(random.randint(0, len(space) - 1), id))
|
||||
for id in range (0, number_of_cycles):
|
||||
for i in range (0, renew_length):
|
||||
if renew[i] == 0:
|
||||
renew[i] = id
|
||||
break
|
||||
# là où les local_thread qui se terminent ont écrit un zéro,
|
||||
# les local_thread nouvellement créés devraient apparaitre !?
|
||||
t = Thread(target=local_thread, args=(random.randint(0, len(arrows) - 1), id))
|
||||
t.start()
|
||||
time.sleep(1)
|
||||
print(' ',copy,' < initial global state (to compare)')
|
||||
|
|
Loading…
Reference in New Issue