VC4.0 Multithreaded comm port I/O
Posted on 1997-03-03
I am writing a Visual C++ 4.0 app that requires the use of comm port I/O. Basically, the app has three threads; one (thread 1) that sits and watches the comm port for incoming data and immediately puts it in a buffer, one (thread 2) that processes the data that came in from thread 1, and one (thread 3) that generates data and writes it to the comm port.
The problem is, if I disable thread 3, so that it is not writing any data to the comm port, it is able to run fine. However, once I enable thread 3, so that it is both writing to the comm port and reading from the comm port, I have some times where some bytes are missing from the incoming data stream. (I verified this by inspecting the data at the remote end before it got transmitted). Not that they are corrupted, just flat out missing, and this is over a null modem cable.
I am using WriteFile and ReadFile (overlapped IO) to interface with the comm ports. Since I check the data right before it goes in and right after it comes out, I start to feel the need to check what's going on at a deeper level inside the OS.
Any advice would be appreciated.