
Hi,
I'm using boost 1.33.1 on multi-processor plateform (2 Pentium4 3.2 GHz)
and Windows XP SP2 (compiled with MinGW).
I wrote a MessageQueue class which use boost::mutex and boost::condition
to wait for message and notify message reception (see code below)
I made a little test that create 2 boost::thread sending and receiving
messages in 2 queues.
The access violation is produced in the "WaitForSingleObject" method
called by "condition_impl::do_wait"
Have you ever meet this problem?
Eric Colleu
------messageQueue.cpp-----START
#include <iostream>
#include "messageQueue.hpp"
namespace util
{
MessageQueue::MessageQueue(void)
: m_mutex()
, m_condition()
, m_queue()
, m_cancel(false)
{
}
MessageQueue::~MessageQueue(void) throw()
{
}
void MessageQueue::push(MessageHandle message)
{
boost::mutex::scoped_lock lock(m_mutex);
m_queue.push(message);
m_condition.notify_all();
}
MessageHandle MessageQueue::pop(const boost::xtime& delay)
{
boost::mutex::scoped_lock lock(m_mutex);
while (m_queue.size() == 0)
{
if (!m_condition.timed_wait(lock, delay))
{
throw MsgTimeout("timeout in pop message");
}
}
if(m_cancel) {
m_cancel = false;
throw MsgWaitCancelled("Wait Event cancelled");
}
MessageHandle msg = m_queue.front();
m_queue.pop();
return msg;
}
MessageHandle MessageQueue::pop(void)
{
boost::mutex::scoped_lock lock(m_mutex);
while (m_queue.size() == 0 && ! m_cancel) {
m_condition.wait(lock);
}
if(m_cancel) {
m_cancel = false;
throw MsgWaitCancelled("Wait Event cancelled");
}
MessageHandle msg(m_queue.front());
m_queue.pop();
return msg;
}
int MessageQueue::size(void)
{
boost::mutex::scoped_lock lock(m_mutex);
return m_queue.size();
}
void MessageQueue::cancel_wait(void)
{
boost::mutex::scoped_lock lock(m_mutex);
m_cancel = true;
m_condition.notify_all();
}
}
------messageQueue.cpp-----END
------messageQueue.hpp-----START
#if defined(CORE_UTIL_QUEUE_MESSAGEQUEUE_CYCLE)
#error Header cyclic inclusion detected.
#endif // defined(CORE_UTIL_QUEUE_MESSAGEQUEUE_CYCLE)
#define CORE_UTIL_QUEUE_MESSAGEQUEUE_CYCLE
#if !defined(CORE_UTIL_QUEUE_MESSAGEQUEUE_HPP)
#define CORE_UTIL_QUEUE_MESSAGEQUEUE_HPP
// ===================================================================
#include <queue>
#include