I have some code here that crashes (AV) sometimes and I can't figure out why, although there are some strange things in there.
There's an std::queue object that's tested for empty first.
If it is empty the application will wait 10milliseconds for a message to arrive and if not it returns. If there was a message or there is a message now the first one is taken from the queue, processed and deleted.
Here's the code:
if (Messages.size() == 0)
{
if ( ! MessageArrived() )
return;
}
Message* msg = Messages.front();
ProcessMessage(*msg);
delete msg;
Messages.pop();
The code crashes on Messages.front();
Now I was thinking if the deletion of msg goes wrong because it happens before the pop() or because this code is threaded that something goes wrong.
Anybody has some theories about this?