Deutsch   English   Français   Italiano  
<v5i9qr$2co9k$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et99 <et99@rocketship1.me>
Newsgroups: comp.lang.tcl
Subject: Re: Thread with -async exits prematurely
Date: Wed, 26 Jun 2024 16:56:10 -0700
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <v5i9qr$2co9k$1@dont-email.me>
References: <6672b7d6$0$705$14726298@news.sunsite.dk>
 <v4uru4$21ajj$1@dont-email.me> <667c6991$0$706$14726298@news.sunsite.dk>
 <v5i3p0$2bch1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 27 Jun 2024 01:56:12 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d2948b1cd65fc4234ee78721ac3f1886";
	logging-data="2515252"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+g4g/9VXscGqPfrHhCn5kC"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
 Thunderbird/102.6.1
Cancel-Lock: sha1:d70ucEyohlnomtRnk7MKRaRpfKs=
In-Reply-To: <v5i3p0$2bch1$1@dont-email.me>
Content-Language: en-US
Bytes: 2985


> 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

--------