Boost logo

Boost Users :

Subject: [Boost-users] Interrupting interprocess::message_queue::receive
From: Michael Herrmann (mherrmann.at_at_[hidden])
Date: 2012-04-12 06:25:12


Hi all,

I am receiving messages from a message_queue via the blocking
receive(...)-method from a separate boost::thread. When I interrupt this
thread, the receive(...)-method never returns (not even with an
thread::thread_interrupted exception). Am i doing something wrong or
could this be a bug in message_queue?

The situation I am talking about is illustrated by the following program
never returning:

     #include <boost/thread.hpp>
     #include <boost/interprocess/detail/config_begin.hpp>
     #include <boost/interprocess/ipc/message_queue.hpp>
     #include <iostream>
     #include <vector>

     using namespace boost::interprocess;

     void receive() {
         try {
             message_queue mq(open_or_create, "message_queue", 100,
sizeof(int));

             unsigned int priority;
             message_queue::size_type recvd_size;

             int number;

             std::cout << "Trying to receive one int..." << std::endl;
             mq.receive(&number, sizeof(number), recvd_size, priority);
         } catch(interprocess_exception &ex) {
             message_queue::remove("message_queue");
             std::cout << "Exception occurred: " << ex.what() << std::endl;
         } catch(boost::thread_interrupted &ex) {
             std::cout << "Thread interrupted. " << std::endl;
         }
     }

     int main() {
         message_queue::remove("message_queue");
         boost::thread t(receive);
         t.interrupt();
         t.join();
     }

     #include <boost/interprocess/detail/config_end.hpp>

Thanks!

Michael


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