I have an administrative thread that starts several worker threads and collates the data they produce, and I am having trouble stopping it.
Its run() loop basically looks like this:
void run()
{
runflag = true;
while(runflag)
{
take_buffers( in_fifo );
nw = start_workers(); // nw is number of active workers
exec(); // run event loop
put_buffers( out_fifo);
}
}
The event handler simply counts remaining workers:
void worker_done()
{
--nw;
if(nw <= 0) exit(); // break event loop
}
The stop() routine, to be called of course from other threads, looks something like this:
bool stop()
{
runflag = false;
in_fifo.flush();
out_fifo.flush();
return wait(500);
}
The fifo flush routines will unblock any thread waiting on a fifo operation.
Problem is, stop() is always returning false, that is, the thread did not stop, and it appears that the reason is that it is stuck in its event loop. However, the thread does stop spontaneously shortly after stop() returns. So I am wondering, does QThread::wait() somehow stop the thread's event processing, or prevent the delivery of queued signals? Or does anyone know of another reason for this odd behavior?
Qt 4.8(MinGW) on Windows Vista.
Bookmarks