Skip to content

Instantly share code, notes, and snippets.

@bovine
Created November 11, 2016 18:17
Show Gist options
  • Save bovine/6215d99c24d5b199c79bef9a2eb3b300 to your computer and use it in GitHub Desktop.
Save bovine/6215d99c24d5b199c79bef9a2eb3b300 to your computer and use it in GitHub Desktop.
tpool::release hangs if any of the thread pool's workers have exited
#!/usr/local/bin/tclsh
package require Thread
# initialize the thread pool
set mypool [tpool::create -minworkers 1 -maxworkers 5]
# queue up something that exits the thread
tpool::post $mypool "puts \"hello\"; thread::exit"
puts "releasing pool (this hangs)"
tpool::release $mypool
@bovine
Copy link
Author

bovine commented Nov 11, 2016

This is because TpoolRelease blindly signals and waits for the workers to exit, without checking if they are actually still running: https://github.com/tcltk/thread/blob/master/generic/threadPoolCmd.c#L1650

@bovine
Copy link
Author

bovine commented Nov 11, 2016

admittedly, using thread::exit within a tpool is not a normal or recommended activity, but maybe this should be handled and detected better.

@bovine
Copy link
Author

bovine commented Nov 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment