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. Inverse Of Semaphore

Inverse Of Semaphore

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
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.
  • Y Offline
    Y Offline
    yccheok
    wrote on last edited by
    #1

    Hi all, Semaphore give us the following behavior count thread state ---------------------------- 3 -> no wait 2 -> no wait 1 -> no wait 0 -> WAIT However, I am looking for some tool which enable me to do this : count thread state ---------------------------- 3 -> WAIT 2 -> WAIT 1 -> WAIT 0 -> no wait I know that I can achieve my objective with the combination of : while(WaitForSingleObject(semaphore, 0) == WAIT_OBJECT_0) { WaitForSingleObject(event, INFINITE); } When the other instances start, they each increments the semaphore with ReleaseSemaphore(). When they exit, each decrements the semaphore counter and fires the event. The problem with this approach is, the first instance would hang if any of the other instances terminates abnormally. Any better suggestion, which I can achieve my objective by just using a single primitive tool? Thanks

    H 1 Reply Last reply
    0
    • Y yccheok

      Hi all, Semaphore give us the following behavior count thread state ---------------------------- 3 -> no wait 2 -> no wait 1 -> no wait 0 -> WAIT However, I am looking for some tool which enable me to do this : count thread state ---------------------------- 3 -> WAIT 2 -> WAIT 1 -> WAIT 0 -> no wait I know that I can achieve my objective with the combination of : while(WaitForSingleObject(semaphore, 0) == WAIT_OBJECT_0) { WaitForSingleObject(event, INFINITE); } When the other instances start, they each increments the semaphore with ReleaseSemaphore(). When they exit, each decrements the semaphore counter and fires the event. The problem with this approach is, the first instance would hang if any of the other instances terminates abnormally. Any better suggestion, which I can achieve my objective by just using a single primitive tool? Thanks

      H Offline
      H Offline
      Hans Dietrich
      wrote on last edited by
      #2

      Jeffrey Richter has written about this here.

      Best wishes, Hans


      [CodeProject Forum Guidelines] [How To Ask A Question] [My Articles]

      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