How to terminate the local threads ? Trying to circumscribe the problem...

This commit is contained in:
Jean Sirmai 2021-03-31 08:19:25 +00:00
parent a467610eae
commit 0450c5de81
1 changed files with 9 additions and 5 deletions

View File

@ -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 # 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 # 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 # 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) # 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 # 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) 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 = [] renew = []
done = [] done = []
@ -50,13 +52,14 @@ def disp(coord, id, start, prev, next):
def local_thread(coord, id): def local_thread(coord, id):
start = datetime.now().timestamp() start = datetime.now().timestamp()
val = random.randint(1,1000) 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] prev = arrows[coord]
next = arrows[coord] = 10 + val % 89 # ou n'importe quelle autre modification !... next = arrows[coord] = 10 + val % 89 # ou n'importe quelle autre modification !...
done.append(id) done.append(id)
for i in range(0, renew_length): for i in range(0, renew_length):
if renew[i] == id: if renew[i] == id:
renew[i] = 0 renew[i] = 0
# time.sleep(100000) faute de savoir les arrêter, j'essaie de les "endormir"... mais ça ne marche pas !
break break
disp(coord, id, start, prev, next) disp(coord, id, start, prev, next)
@ -68,9 +71,11 @@ for id in range (0, number_of_cycles):
break break
# là où les local_thread qui se terminent ont écrit un zéro, # là où les local_thread qui se terminent ont écrit un zéro,
# les local_thread nouvellement créés devraient apparaitre !? # 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 = Thread(target=local_thread, args=(random.randint(0, len(arrows) - 1), id))
t.start() t.start()
time.sleep(1) time.sleep(1.5)
print(' ',copy,' < initial global arrows state (to compare)') print(' ',copy,' < initial global arrows state (to compare)')
print('history: ',done) # done.sort() # print(done) 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**. 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**' Pour cela, il génère des threads de calcul locaux ou '**local_threads**'