AMDG 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, &read_count); data = (char *)((DEVICE_DATA*)buffer)->data; }
boost::mutex::scoped_lock client_lock(client_mutex); { _client.processMessage(data); }
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? In Christ, Steven Watanabe