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@gmail.com>
To:
boost-users@lists.boost.org
Date:
04/12/2012 03:51 AM
Subject:
[Boost-users]
Interrupting interprocess::message_queue::receive
Sent by:
boost-users-bounces@lists.boost.org
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@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users