Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Thread pool help

38 views
Skip to first unread message

Simon Geard

unread,
Jun 24, 2018, 12:30:10 PM6/24/18
to
I've been trying to create a thread pool but am failing but can't see
what I'm doing wrong:

package require Thread

proc ex_run {} {
puts "Exiting"
}

proc st_run {} {
puts "Starting"
}

proc run {a} {
puts "Run: a = $a"
}

# The following fails even though st_run is defined
set tp [tpool::create -initcmd st_run -exitcmd ex_run]

for {set i 1} {$i <= 7} {incr i} {
lappend jlist [tpool::post $tp "run $i"]
}

puts "Jobs: $jlist"
tpool::wait $tp $jlist jrem
puts "All done"


I've tried many argument combinations in the above but haven't found one
that works. Any help greatly appreciated.

Simon

Rich

unread,
Jun 24, 2018, 1:03:12 PM6/24/18
to
Simon Geard <si...@whiteowl.co.uk> wrote:
> proc ex_run {} {
> puts "Exiting"
> }
>
> proc st_run {} {
> puts "Starting"
> }
>
> # The following fails even though st_run is defined
> set tp [tpool::create -initcmd st_run -exitcmd ex_run]

Read the -initcmd and -exitcmd part of the tpool manpage carefully:

-initcmd script
Sets a Tcl script used to initialize new worker thread.

-exitcmd script
Sets a Tcl script run when the idle worker thread exits.

Then note that your -initcmd and -exitcmd arguments are "proc names"
not "scripts".

Simon Geard

unread,
Jun 24, 2018, 1:16:35 PM6/24/18
to
Thanks very much for that. I had just figured out that the following works:

set tp [tpool::create -initcmd {
proc run {mu} {
puts "mu = $mu"
}
}]
#
for {set i 1} {$i <= 7} {incr i} {
lappend jlist [tpool::post $tp "run $i"]
}
tpool::wait $tp $jlist


0 new messages