I have a C++98 project that uses Boost-Thread. The main thread creates 12 threads like this:
for(int i=0;i<numCPU;++i)
{
vThreads.push_back(new boost::thread(boost::bind(&TControl::startCPU,this,i,fnp)));
}
and the worker threads run as long as getWork() returns workunits:
void startCPU(int id,StartFn fnp)
{
unused(id);
while(true)
{
WU_TYPE* pWU(getWork());
if(pWU==NULL) return;
CALL_MEMBER_FN(pWU,fnp)();
}
}
Certain workunits may run very long. The goal is now to kill workunits that have already more than 60 minutes runtime so that the thread (that runs void startCPU() ) can start a new workunit.
Initially I thought that this can be done by signals, i.e., the main thread could raise a signal every minute and a signal handler inside each thread could throw an exception for overdue workunits. But after a bit reading it doesn't seem to work like this because signals raised from one thread do not launch the signal handler of another thread, right? What is an appropriate technique to achieve this goal?
Note: C++11 is not available, the software must compile on old systems.