×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

C win32 threads

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?

RE: C win32 threads

The boolean would work if the thread is looping around and not actually waiting.
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

Sounds you have at least threads running. Once either thread you create gets input, it posts a message to your primary thread (using ::PostThreadMessage) asking your primary thread to terminate the other one.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources