Created
November 11, 2016 17:11
-
-
Save bovine/53ab96cbe2572ea1c758d604d33a1c4a to your computer and use it in GitHub Desktop.
tpool::post -nowait does not ever create more than 1 worker thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Opened as bug at http://core.tcl.tk/thread/tktview/d9c95d3ed3f9c67dae738c7dd062fa9a7a6b8cb7