C win32 threads
C win32 threads
(OP)
I am creating two threads, one is waiting for commands at the command line and the other is checking a UDP socket. Whichever happens first, I want to kill the other thread. For example, if user enters something from the commandline, the other thread waiting for UDP packets should exit.
I am using MS visual studio.
How can I do that?
I am using MS visual studio.
How can I do that?





RE: C win32 threads
I would do a WaitForMultipleObjects instead of the WaitForSingleObject in you waiting threads and create the special mutex or a semaphore to wait for so that the thread that receives input first can set the boolean flag and then signal this mutex to unblock the other thread.
You also need to think through the race conditions.
BUT here is another idea - using the same WaitForMultipleObjects can try to wait for input from both sources in the same thread - you are not actually doing anything simultaneous anyway. And once the wait returns - you can check which event unblocked it and perform the appropriate whatever. that way no need for two threads. Unless of course you have other reasons to use 2 threads.
HTH.
RE: C win32 threads