I have the following code and it terminates as expected. When I call the destructor it interrupts the thread.
But if I change the this_thread::sleep to this_thread::yield the join() never happens and the program hangs.
I must be misunderstanding yield. But I really don’t want a sleep if possible.
Thanks,
John
MessageQueueHandler::~MessageQueueHandler()
{
// Terminate the thread
pMessageQueueInputThread->interrupt();
pMessageQueueInputThread->join();
delete pMessageQueueInputThread;
}
void MessageQueueHandler::MessageQueueInputThread()
{
unsigned int receivedSize;
unsigned int priority;
char buffer[queueMaximumMessageSize];
boost::this_thread::interruption_enabled();
try
{
while(1)
{
// Process all messages in the queue
while(inputMessageQueue->try_receive(buffer, queueMaximumMessageSize, receivedSize, priority))
{
BaseMessage * msg = reinterpret_cast<BaseMessage*>(buffer);
callbackTable->DispatchMessage(msg);
boost::this_thread::interruption_point();
}
// Give other threads a chance to run
// This is also an interruption point
boost::this_thread::sleep(boost::posix_time::millisec(50)); çHere
}
}
catch(boost::thread_interrupted const&)
{
return;
}
}
___________________________________
John Davies
Contractor
Home Respiratory Care
Philips Home Healthcare Solutions
1740 Golden Mile Highway
Monroeville, PA 15146
Email: john.davies@philips.com
Fax: 724-387-4109