Re: Thread with -async exits prematurely

Liste des GroupesRevenir à cl tcl 
Sujet : Re: Thread with -async exits prematurely
De : et99 (at) *nospam* rocketship1.me (et99)
Groupes : comp.lang.tcl
Date : 27. Jun 2024, 00:56:10
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5i9qr$2co9k$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1

Luis Mendes <luisXXXlupeXXX@gmail.com> wrote:

1. Regarding vwait
-snip-
Care must be taken to -NOT- do any [update] calls or a [vwait] on another variable any time between the thread::send calls and the vwait on the variable sync - since all threads are setting the same variable. If the event loop is entered with a few queued up events to set the variable sync, then some of them will not be processed and the threads will not be killed off.
Here's an example of that happening, where the timing is such that the threads return and set sync before they are vwait'd on:
------------------------
set sync 0
package require Thread
for {set n 0} {$n < 5} {incr n} {
     set tid [thread::create]
     puts "created tid $tid"
     thread::send -async $tid {after 120; set foo [thread::id]} ::sync
}
puts "before waiting with sync = $::sync"
set ::avar 0
after 100 {set ::avar 1}
vwait ::avar
for {set m 0} {$m < 5} {incr m} {
     vwait ::sync
     puts "m=$m after waiting for sync with sync now = $::sync"
}
------------------------
And here is the output of two runs:
created tid tid0000578C
created tid tid00001A68
created tid tid0000555C
created tid tid00005B14
created tid tid00000810
before waiting with sync = 0
m=0 after waiting for sync with sync now = tid00005B14
m=1 after waiting for sync with sync now = tid00000810
--------
created tid tid00003464
created tid tid0000558C
created tid tid00002A90
created tid tid000045F0
created tid tid00003418
before waiting with sync = 0
m=0 after waiting for sync with sync now = tid0000558C
m=1 after waiting for sync with sync now = tid00002A90
m=2 after waiting for sync with sync now = tid000045F0
m=3 after waiting for sync with sync now = tid00003418
--------

Date Sujet#  Auteur
19 Jun 24 * Thread with -async exits prematurely9Luis Mendes
19 Jun 24 +* Re: Thread with -async exits prematurely7Rich
26 Jun 24 i`* Re: Thread with -async exits prematurely6Luis Mendes
26 Jun 24 i `* Re: Thread with -async exits prematurely5Rich
27 Jun 24 i  `* Re: Thread with -async exits prematurely4et99
28 Jun 24 i   `* Re: Thread with -async exits prematurely3Luis Mendes
28 Jun 24 i    +- Re: Thread with -async exits prematurely1Rich
28 Jun 24 i    `- Re: Thread with -async exits prematurely1et99
19 Jun 24 `- Re: Thread with -async exits prematurely1et99

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal