Hello,
I'm writing a multithreaded server on Unix using boost::thread. The
basic operation is fairly straightforward; a master thread starts up
worker threads, and coordinates various management tasks using
condition variables.
As with most Unix servers, the server is shut down with an OS signal
telling the server to shut down. The server catches this signal, then
simply calls exit(1). Any important cleanup happens in the
destructors of global variables, so it will happen properly no matter
how the server exits.
One object which is always cleaned up is the object for the master
thread. The master thread sets a flag, then does a notify_all() on
some condition variables to tell the other threads to shut down,
The problem I'm having is that if the master thread is waiting on a
condition variable when the signal arrives, and the destructor does a
notify_all() on that condition variable, then the destructor for the
boost::condition variable hangs.
For example, if I run the included code and hit CTRL-C after a short
bit, I get this output:
Waiting...
^C
Caught signal 2
Destroyed ThreadTest
Running destructor 1
[ ... hangs ... ]
Here is the program:
#include <iostream>
#include