diff --git a/Concurrent Programming.py b/Concurrent Programming.py index 857ff6e..18c49f5 100644 --- a/Concurrent Programming.py +++ b/Concurrent Programming.py @@ -1,3 +1,35 @@ +from threading import Thread +import random # juste pour que le temps de travail des threads soit aléatoire +import time + + +arrows = [] +local_threads_number = 10 + +def init(): + for j in range(0, local_threads_number): + arrows.append(j % 10) + print(arrows,' < initial arrows state') + +def local_thread(coord): + while True: + time.sleep(random.randint(0,1)) + arrows[coord] = (arrows[coord] + 1) % 10 + print(arrows,' ',coord) + return + +init() # Scheduler +for i in range(0, local_threads_number): + t = Thread(target=local_thread, args=(range(i,i+1))) + # argument after * must be an iterable, not int < ? + t.start() + +# Je ne l'isole pas dans un autre fichier +########################################################################################### + + + + from threading import Thread from datetime import timedelta from datetime import datetime