I\'ve created two threads A & B using CreateThread windows API. I\'m trying to send the data from thread A to B.
I know I can use Event object and wait for the Event
First of all, you should keep in mind that Windows provides a number of mechanisms to deal with threading for you: I/O Completion Ports, old thread pools and new thread pools. Depending on what you're doing any of them might be useful for your purposes.
As to "sending" data from one thread to another, you have a couple of choices. Windows message queues are thread-safe, and a a thread (even if it doesn't have a window) can have a message queue, which you can post messages to using PostThreadMessage
.
I've also posted code for a thread-safe queue in another answer.
As far as having the thread continue executing, but take note when a change has happened, the typical method is to have it call WaitForSingleObject
with a timeout value of 0, then check the return value -- if it's WAIT_OBJECT_0
, the Event (or whatever) has been set, so it needs to take note of the change. If it's WAIT_TIMEOUT
, there's been no change, and it can continue executing. Either way, WaitForSingleObject
returns immediately.