Description
When using C exit
function, the IlmThreadpool deadlocks during shutdown on Windows.
This is happening because the worker threads have not run yet (and so have not posted on the "started" semaphore) when they get killed.
During shutdown, that semaphore deadlocks as it waits for N threads (but it might not have been posted on all workers)
This is especially noticeable when oversubscribing threads (for example 10 threads on a 2 core machine).
I have never seen it deadlock when calling the exit function from the main thread (though not sure if that means it cannot happen or just random coinsidence) and Windows seems to be the only platform affected.
This was initially discovered when trying to get the OpenImageIO test suite to run on Windows yet the following code can be used to reproduce (you might have to run it a couple times because, well threading :) )
int main(int argc, char** argv)
{
std::thread t([]() {exit(-1); });
Imf::setGlobalThreadCount(5);
t.join();
}