Boost logo

Boost Users :

Subject: Re: [Boost-users] Interrupting interprocess::message_queue::receive
From: Michael Herrmann (mherrmann.at_at_[hidden])
Date: 2012-04-13 14:22:50


Hi Aaron,

thank you for your reply. It's too bad, from looking at the source code
of message_queue I would have thought it should be possible -
message_queue itself is waiting on an interprocess_condition called
m_cond_recv. I'm surprised that interrupting such a condition is
apparently not possible, though I'm sure there are good reasons for it.
Let's hope this gets fixed soon!

Cheers,
Michael

On 13/04/2012 19:40, Aaron_Wright_at_[hidden] wrote:
> I was caught by this same thing a while ago. I was told that
> interrupting interprocess waits is not trivial and is not implemented.
> I just had to switch to a timed wait and sort of poll for the interrupt.
>
> ---
> Aaron Wright
>
>
>
>
> From: Michael Herrmann <mherrmann.at_at_[hidden]>
> To: boost-users_at_[hidden]
> Date: 04/12/2012 03:51 AM
> Subject: [Boost-users] Interrupting interprocess::message_queue::receive
> Sent by: boost-users-bounces_at_[hidden]
> ------------------------------------------------------------------------
>
>
>
> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users



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