I am using the following to convert serial data over a com port into a deque. The problem I am having is that while data is streaming and things get busy the program tends to crash on this. It works fine for awhile, sometimes hours, it is a multithreaded program, so this may not be the only issue, I was just wondering if anyone has some suggestions...

for(i=0 ; i< bytes_read ; i++) //Convert from BYTE array to Byte deque STL
packetStream.push_back(read);

This method would make life easier for me when processing the streaming data so I don't need to keep track of the pointers myself. I am also unable to read directly into the deque because the ReadFile call goes into it's own buffer (read[])...

Are you using packetStream object in another thread? If yes, you need to sinchronize access to that vector between the two threads. One way to do it is to create a semiphore. MS-Windows has several other ways to sinchronize the objects too.

Well I thought I was successfully using a mutex and signaling the thread with the wxwidgets package I am using for the GUI. But I noticed if I put that thread to sleep for a few milliseconds, the program doesn't crash (yet..). So obviously both threads were accessing the same object...

Been having troubles with this package using threads, might just have to break down and do the threading with the windows API.

Thank you for the suggestion Dragon, I guess it was kinda obvious, but it got me thinking again, lol.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.