MultiThreading in MFC for modem drivers I've run into a slight issue while trying to design Modem drivers (1200 baud) to be exact.
Although we have spent a fair amount of hours in the environment, we havent been introduced to threading. I understand the concept and the hooks around launching threads, I've just never actualy gotten one working properly.
My situation is as follows, using a single path application with multiple timers just wont cut it for these modems. The shortest timer is 1 ms and those little modems chunck out characters MUCH faster than that. The issue become that the software is almost unable to catch all the incoming characters, and formating packets with STX, ETX checksums and other control characters become a hastle because we are never guarenteed that the full packet was received properly. The modem keeps missing either a piece of data or one of the control chars and almost always locks the transmission until they can finaly resync. (Yes there is error checking and retransmission on an ACK/NACK system.)
#1 I Am wondering if it is prudent/possible to launch a thread on init or in a constructor that can query the UART to check if a character has come in, and if so, GRAB it right away so that the next incoming character doesnt clobber the previous one.
#2 How do I go about this? The MSDN site is very vague and has me running in circles.
So far I know that I need to create a control function to be launched ex UINT MyThread( LPVOID lparam), and launch that as a worker thread in the background AfxBeginThread(MyThread, this->hWnd,??) <--- the rest becomes quite confusing.
Im assuming somewhere in there I have to throw in a custom message ex: WM_USER + 1 type of defenition as to catch messages from that thread?
Any further than that and I'm wandering in the dark.
Any help/suggestions would be much appreciated. |