diff --git a/Concurrent Programming b/Concurrent Programming index 27491d5..857ff6e 100644 --- a/Concurrent Programming +++ b/Concurrent Programming @@ -8,11 +8,13 @@ local_threads_number = 7 # in a more realistic model: local threads number # then, locations would be picked at random in this great global arrows state # but the goal of this "micro-model" is not to explore the algorithms of choice of an arrow in the state # it is to fix the way the scheduler terminates the local threads that have done their task + # # in a realistic model, the number of cycles is infinite (the user decides when to stop a running simulation) # and the size of the "renew" list (the list of the active local threads) depends on the computational power available - # this "micro-model" allows to explore the ineractions [scheduler <-> local threads] when the the "renew" list size varies + # this "micro-model" allows to explore the ineractions [scheduler <-> local threads] when the the "renew" list size varies + # renew_length = 16 # renew_length can vary from 1 to number_of_cycles (if more, a part of it remains empty) -number_of_cycles = 20 # in a realistic model: number_of_cycles >> renew_length +number_of_cycles = 24 # in a realistic model: number_of_cycles >> renew_length renew = [] done = [] @@ -50,13 +52,14 @@ def disp(coord, id, start, prev, next): def local_thread(coord, id): start = datetime.now().timestamp() val = random.randint(1,1000) - time.sleep(val / 1000) + time.sleep(val / 1000) # pourquoi y a-t-il toujours au moins un local thread qui travaille (ou dort !...) pendant toute la durée de la simulation ? prev = arrows[coord] next = arrows[coord] = 10 + val % 89 # ou n'importe quelle autre modification !... done.append(id) for i in range(0, renew_length): if renew[i] == id: renew[i] = 0 + # time.sleep(100000) faute de savoir les arrêter, j'essaie de les "endormir"... mais ça ne marche pas ! break disp(coord, id, start, prev, next) @@ -68,9 +71,11 @@ for id in range (0, number_of_cycles): break # là où les local_thread qui se terminent ont écrit un zéro, # les local_thread nouvellement créés devraient apparaitre !? + # c'est peut-être un problème d'affichage: comme les local_threads ne sont pas terminés, + # ils continuent à afficher un zéro dans "renew" ? t = Thread(target=local_thread, args=(random.randint(0, len(arrows) - 1), id)) t.start() -time.sleep(1) +time.sleep(1.5) print(' ',copy,' < initial global arrows state (to compare)') print('history: ',done) # done.sort() # print(done) @@ -79,7 +84,6 @@ print('history: ',done) # done.sort() # print(done) - """ Le **scheduler**, ou processus principal, effectue un calcul sur l'**état global**. Pour cela, il génère des threads de calcul locaux ou '**local_threads**'