Boost Users :
Subject: Re: [Boost-users] Simple threading question (I hope)
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-11-06 17:48:19
Alec Munro wrote:
> I've got a COM dll that communicates over USB. It relies on a specific
> USB driver for communication. When I initiate communication with the USB
> driver, I can register an object to accept notifications of USB events.
> Each of these notifications occurs on a new thread.
> When this object receives a "new data" event, I read the data from the
> USB channel, and then send the data to a different object to be
> processed. This looks like this:
> boost::mutex::scoped_lock channel_lock(channel_mutex);
> _channel->ReadPacket((unsigned char *)buffer, BUFFER_LENGTH,
> data = (char *)((DEVICE_DATA*)buffer)->data;
> boost::mutex::scoped_lock client_lock(client_mutex);
> My question is if I receive several packets while I am in
> processMessage(), will those packets be passed to processMessage() in
> the order they arrive?
I don't see how you can guarantee this.
Suppose that that thread A reads the data and is then pre-empted.
Thread B, then reads its data and continues on to process it.
Thread A now processes its data.
Even if threads acquire the mutex in the same order that they
reach it (which is not guaranteed), how do you guarantee that
they reach the mutex in the right order?
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