Boost logo

Boost Users :

Subject: [Boost-users] Threading question
From: Davies, John (john.davies_at_[hidden])
Date: 2013-09-26 19:16:54


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_at_[hidden]
Fax: 724-387-4109

________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net