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 186957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:44:19+00:00 2026-05-11T15:44:19+00:00

Suppose that ThreadA and ThreadB both call WaitOne() in that order on the same

  • 0

Suppose that ThreadA and ThreadB both call WaitOne() in that order on the same AutoResetEvent. When the event is set, why does ThreadB get released instead of ThreadA?

I ran a test to find out what happens when you set an AutoResetEvent on which mutiple threads are waiting:

    private static void Test()     {         // two threads - waiting for the same autoreset event         // start it unset i.e. closed i.e. anything calling WaitOne() will block         AutoResetEvent autoEvent = new AutoResetEvent(false);          Thread thread1 = new Thread(new ThreadStart(WriteSomeMessageToTheConsole));         thread1.Start();  // this will now block until we set the event          Thread thread2 = new Thread(new ThreadStart(WriteSomeOtherMessageToTheConsole));         thread2.Start();  // this will now also block until we set the event          // simulate some other stuff         Console.WriteLine("Doing stuff...");         Thread.Sleep(5000);         Console.WriteLine("Stuff done.");          // set the event - I thought this would mean both waiting threads are allowed to continue         // BUT thread2 runs and thread1 stays blocked indefinitely         // So I guess I was wrong and that Set only releases one thread in WaitOne()?         // And why thread2 first?         autoEvent1.Set();     } 

The code is of course not useful, it’s just a simple example.

  • 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. 2026-05-11T15:44:19+00:00Added an answer on May 11, 2026 at 3:44 pm

    IIRC, which thread is released by an auto-reset event is unspecified. As everyone else mentioned, you want a manual reset event if you want to broadcast a condition. If you want to release an exact number (say exactly 3 of n), then you probably want to use a semaphore.

    If you really want to dig into why the order might be different than you would expect, take a look at ‘Windows Internals’ or anything that Mark Russinovich has written. Chances are that he explains the wait order on executive resources somewhere.

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

Sidebar

Ask A Question

Stats

  • Questions 137k
  • Answers 137k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can access any information stored such as ConnectionStrings,AppSettings and… May 12, 2026 at 7:26 am
  • Editorial Team
    Editorial Team added an answer $(function(){ $(".moo").each(function(){ $(this).attr("href",$(this).attr("href")+"?iframe=true&width=600&height=300"); }); }); that should work I think May 12, 2026 at 7:26 am
  • Editorial Team
    Editorial Team added an answer Either do something like this: mySprite.addEventListener("mouseDown", mouseDownHandler); stage.addEventListener("mouseUp", mouseUpHandler); protected… May 12, 2026 at 7:26 am

Related Questions

I'm currently trying to pass a mono threaded program to multithread. This software do
If I have a deeply immutable type (all members are readonly and if they
In any DBMS that's more than half-baked, there is a distinction between a read
I have a python GUI app that uses a long running function from a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.