Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9222081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:43:49+00:00 2026-06-18T03:43:49+00:00

spoiler note: the question is the last phrase. In C#, the classical pattern to

  • 0

spoiler note: the question is the last phrase.

In C#, the classical pattern to use a condition variable is like this:

lock (answersQueue)
{
    answersQueue.Enqueue(c);
    Monitor.Pulse(answersQueue); // condition variable "notify one".
}

and some other thread:

lock (answersQueue)
{
    while (answersQueue.Count == 0)
    {
        // unlock answer queue and sleeps here until notified.
        Monitor.Wait(answersQueue);
    }
    ...
}

that’s an example taken from my code.
if I place the Pulse outside of the lock scope, it doesn’t compile.
however, it is the correct way:
c.f:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms686903(v=vs.85).aspx
and:
http://www.installsetupconfig.com/win32programming/threadprocesssynchronizationapis11_7.html
(search for “inside”)

And indeed it is idiotic to signal the sleeping thread when you still are in your critical section. Because the sleeping thread CAN’T wake up (not immediately), BECAUSE it is INSIDE a criticial section as well !

Therefore, I hope that .NET or C# Pulse call is actually just flagging the lock object, so that when it goes out of scope it actually “pulses” the condition variable at this moment. Because otherwise, it would have an optimality issue.

So how come the design of the Monitor object was chosen to be that way ?

Edit:

I found the answer in this paper:
http://research.microsoft.com/pubs/64242/implementingcvs.pdf
section “Optimising Signal and Broadcast” and the previous section about NT kernel and how to make Condition Variable on top of Semaphores, which is the reason for introducing the “darned queues”.
NOW that makes me a better engineer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:43:50+00:00Added an answer on June 18, 2026 at 3:43 am

    And indeed it is idiotic to signal the sleeping thread when you still are in your critical section. Because the sleeping thread CAN’T wake up

    Pulse doesn’t expect to get a thread running; it only expects to move a thread between the 2 queues (waiting and ready). The “not go do something” is part of releasing the lock via Exit (or the end of a lock). In reality, it isn’t an issue because Monitor.Pulse typically happens right before a Wait or an Exit.

    Therefore, I hope that .NET or C# Pulse call is actually just flagging the lock object, so that when it goes out of scope it actually “pulses” the condition variable at this moment. Because otherwise, it would have an optimality issue.

    Again; these are different issues: moving between waiting and ready is one thing; exiting a lock already has all the code to actually activate the next ready thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE (spoiler): This question is answered (see David Carlisle answere below) and it looks
Note that this question contains some spoilers. A solution for problem #12 states that
Spoiler alert: this is a stupid question ;) I have a Rails form where
I have a question about your spoiler in this page: http://jdownloader.org/download/index When i click
This seems like such a simple requirement, that I feel like I am missing
Spoiler alert, this is problem 5 of Project Euler. I am attempting to learn
Spoiler: I am an absolute beginner to C. I quickly threw threw together this
spoiler : This is just another Lucene vs Sphinx vs whatever, I saw that
I added a spoiler class in CSS to use for, well, spoilers. Text is
I'm trying to change a spoiler but i have problem with javascript code This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.