Two thread callbacks on an async serial com port

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dare2k
    New Member
    • Oct 2012
    • 1

    Two thread callbacks on an async serial com port

    Hello,

    I have two threads in C.
    Thread no.1 Parses the stream that is a continuous stream of messages.
    Thread no.2 Sends commands to the stream.
    The communication takes place on a COM serial port.

    When i send a command i send a callback function for that command and parameters for the responses.(in thread 2)

    How can I trigger in thread no.1 this callback when i receive a response that matches on of the responses that i have defined in thread 2?
    Last edited by dare2k; Oct 26 '12, 09:37 AM. Reason: Specifying the problem is for C
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    This is a explained in Jeffrey Richter's book
    Code:
    Windoes via C/C++.
    Essentially in your worker thread you call WaitForSingleOb ject usually with a time allowance and test for an event. If the event does not occur, the thread proceeds (usually in a loop) and then retests for the event.

    THe main thread calls SetEvent to send the event to the worker.

    You need to be careful of shared data so be sure to protect yourself by using critical sections. You may need to read up on this.

    Comment

    Working...