none
How to: Use the Context Class to Implement a Cooperative Semaphore - Bug RRS feed

  • Question

  • The semaphore example has bug which has been on msdn for quite a while. Last time I ran into to it was over a year ago, and now I once again ran into debugging it.

    Please fix it:

          if (!_waiting_contexts.try_pop(waiting))
          {
             Context::Yield();
          }

    Should be:

          while (!_waiting_contexts.try_pop(waiting))
          {
             Context::Yield();
          }


    Thursday, June 21, 2012 9:23 PM

Answers

  • Thanks for taking the time to let us know about this! I apologize that you had to deal with this two times. This must have been a typo when I wrote this example, based on the above comment.

    I fixed and validated this per your suggstion and updated this page and this page. The updates will go live soon as part of a content refresh.

    If you're working with the Visual Studio 2012 version of the content, you'll also see that I updated the calls to InterlockedIncrement and InterlockedDecrement to use std::atomic.

    Again, I apologize for the inconvenience and thanks for pointing this out!

    Friday, June 22, 2012 9:43 PM