Tcl package Thread source code

Artifact [acb30cad5a]
Login

Artifact acb30cad5ab08ada26a50e4927247be18842749d:

Attachment "tpool_nowait_bug.tcl" to ticket [d9c95d3ed3] added by bovine 2016-11-11 23:11:34.
#!/usr/local/bin/tclsh

package require Thread

set threadstart {
    puts "thread started"
    tsv::incr sharedData threadCount
}


# initialize the thread pool
tsv::set sharedData threadCount 0
tsv::set sharedData workersDone 0
set mypool [tpool::create -minworkers 0 -maxworkers 10 -initcmd $threadstart]

# queue up lots of varying duration work.
for {set i 0} {$i < 10} {incr i} {
    tpool::post -detached -nowait $mypool "puts \"work $i\"; after 1000; tsv::incr sharedData workersDone"
}

# wait for all of the work to finish
while {[tsv::get sharedData workersDone] < 10} {
    after 100
}

puts "releasing pool"
tpool::release $mypool

set numThreads [tsv::get sharedData threadCount]
puts "A total of $numThreads threads were created."
if {$numThreads == 1} {
    puts "BAD. All work was done serially."
} else {
    puts "GOOD. Work was done in parallel."
}