Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. WaitForSingleObject and SetEvent

WaitForSingleObject and SetEvent

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    laksh2204
    wrote on last edited by
    #1

    Hi Everyone, I have some confusion with WaitForSingleObject. Is it necessary for a thread to be in wait state to handle an event? for example, Thread1 { SetEvent(event); } Thread2{ while(true) { if(WaitForSingleObject(event, INFINITE)){ SetEvent(event); //event raised again, but handler thread 2 is not in wait now } } } Thanks laksh

    R 1 Reply Last reply
    0
    • L laksh2204

      Hi Everyone, I have some confusion with WaitForSingleObject. Is it necessary for a thread to be in wait state to handle an event? for example, Thread1 { SetEvent(event); } Thread2{ while(true) { if(WaitForSingleObject(event, INFINITE)){ SetEvent(event); //event raised again, but handler thread 2 is not in wait now } } } Thanks laksh

      R Offline
      R Offline
      Roger Stoltz
      wrote on last edited by
      #2

      All synchronization objects works the same way regarding this, e.g. locking a mutex, releasing a semaphore or setting an event. In your case the event will be set until some thread calls any of the wait functions such as ::WaitForSingleObject(). The event may be set up to automatically reset when the thread that waits on the event gets released, or it may be set to be "manual reset" in which case you have to call ::ResetEvent() to set the event in a non-signalled state. But, you have to call any of the waiting functions in order to find out whether the event is signalled or not. You may call ::WaitForSingelObject() with a timeout value of zero in which case the function will return with WAIT_TIMEOUT unless the event was set.

      "It's supposed to be hard, otherwise anybody could do it!" - selfquote
      "High speed never compensates for wrong direction!" - unknown

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups