Thread with -async exits prematurely

Liste des GroupesRevenir à cl tcl 
Sujet : Thread with -async exits prematurely
De : luisXXXlupeXXX (at) *nospam* gmail.com (Luis Mendes)
Groupes : comp.lang.tcl
Date : 19. Jun 2024, 11:49:58
Autres entêtes
Organisation : SunSITE.dk - Supporting Open source
Message-ID : <6672b7d6$0$705$14726298@news.sunsite.dk>
User-Agent : Pan/0.154 (Izium; 517acf4)
Hi all!


My program is working fine when thread::send don't use the -async option.
When it does, all of those created threads exit prematurely.

The pseudo-code I have is this:

===== main file

while 1 {
    ...
    while {nr_live_threads < nr_max_threads} {
        set tid [thread::create $init_script]
        thread::send -async $tid [list sourceFiles ....]
    }
    after 10000
}

===== init_script
set init_script {
    proc sourceFiles {...} {
        source oo.tl
        ns0::runAnsible ....
    }
    thread::wait
}


===== oo.tcl
    namespace eval ns0 {
        proc runAnsible {...} {
            Parse new ...
            vwait ::exit_flag
        }
    }
    oo::class create Parse {
        constructor {...} {
            set chan_ans [open |[list {*}$ansible_comm] r]
            chan configure $chan_ans -blocking 0 -buffering line
            chan event $chan_ans readable [list [self object] parseLine]
        }
        method parseLine {} {
            set status [catch {chan gets $chan_ans line} nchars]
            if {$status == 0 && $nchars >=0} { my processLine $line}
                ;# processLine not shown
            if {$status || [chan eof $chan_ans]} {
                chan configure $chan_ans -blocking 1
                chan event $chan_ans readable {}
                catch {chan close $chan_ans}
                set ::exit_flag 1
            }
        }
    }

This comprises the important parts of the script, I think.
When thread::send does not use `-async`, the `vwait ::exit_flag` works and
the thread is run until the end.
With `-async`, the thread exits shortly after the `thread::send` command.

I've read about `thread::preserve` and `thread::release`, but interpreted
it as necessary when threads have to be orchestrated and some may be
dependent on the results of others.

What I want is really to have several threads launched in the same moment,
at each run of the while loop that checks if the number of active threads
is less than the nr_max_threads.
How can that be accomplished?

Thanks,


Luís

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