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

  • SEARCH
  • Home
  • 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 6084847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:34:16+00:00 2026-05-23T11:34:16+00:00

I’m going through the following article: http://www.albahari.com/threading and I cannot get to realize the

  • 0

I’m going through the following article:

http://www.albahari.com/threading

and I cannot get to realize the difference between an AutoResetEvent and a Semaphore initialized with maximumCount = 1. Just to see if I’m getting things right… is there any difference in these two constructs, given that usage?

Thanks!

  • 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-05-23T11:34:17+00:00Added an answer on May 23, 2026 at 11:34 am

    Yes, there certainly is a difference. A Semaphore is used to throttle access to a resource or block of code. When WaitOne is called a thread will block until a count from the semaphore becomes available. To make a count availabe you would call Release. A semaphore with a maximum count of 1 is often called a binary semaphore. A semaphore of this nature only allows access to a resource or block code from a single thread. You could use a binary semaphore in place of a mutex or monitor. The important thing to remember about the Semaphore is that its state is manually controlled via calls to WaitOne and Release.

    An AutoResetEvent on the other hand is primarily used as a signaling mechanism. One thread will block via a call to WaitOne waiting for a signal. Another thread will call Set to initiate that signal. An ARE publishes this signal to one and only one thread and then immediately resets the ARE to an unsignaled state. The important thing to remember about the AutoResetEvent is that it is manually signaled via a call to Set and automatically reset after when a single call to WaitOne returns.

    So here is a summary of differences:

    • A Semaphore‘s state is manually controlled.
    • A AutoResetEvent‘s state is manually set, but automatically reset.
    • With a Semaphore threads typically balance the Release and WaitOne calls.
    • With a AutoResetEvent one thread is typically designated as the signaler and another is the waiter.
    • A Semaphore throttles access to a resource or block of code.
    • A AutoResetEvent signals a thread to take some action.

    Think of a AutoResetEvent as a door to a hallway. The door will allow one and only one person through the door after receiving a command to do so. Once a person goes through the door it immediately closes and waits for another command. As long as the door keeps receiving new commands the hallway is free to fill with as many people as the number of commands given.

    Think of a Semaphore as a door to the same hallway. The door will allow a certain number of people in the hallway. The door remains open until the hallway reaches its occupancy limit at which time the door closes. After someone leaves the hallway through the other side then this door opens again.

    Update:

    Here is the simplest possible example that demonstrates that something is clearly different.

    static void Main()
    {
        var are = new AutoResetEvent(false);
        are.Set();
        are.Set();
    
        var semaphore = new Semaphore(0, 1);
        semaphore.Release();
        semaphore.Release();
    }
    

    It comes as no surprise that you will get an exception on the second semaphore.Release call whereas the second call to Set passes through just fine. The reason is because an ARE is setting a boolean flag whereas the semaphore is attempting to increase the count.

    The WaitOne methods will work the same way, but the Release and Set methods will not. It is for this reason that a binary semaphore is not interchangable with an ARE. However, an ARE could be interchangable with a binary semaphore in some cases.

    One scenario where there is overlap is in the case of a latch for a single thread.

    public static void Main()
    {
      var latch = new AutoResetEvent(false);
    
      new Thread(
        () =>
        {
          latch.WaitOne(); // Wait for the latch.
        }).Start();
    
      latch.Set(); // Release the latch.
    }
    

    Here is a scenario that can only be satisfied by a AutoResetEvent.

    static void Main()
    {
        var are = new AutoResetEvent(false);
    
        new Thread(
            () =>
            {
                while (true)
                {
                    are.WaitOne();
                    Console.WriteLine("go");
                    Thread.Sleep(2000);
                }
            }).Start();
    
        while (true)
        {
            are.Set();
            Console.WriteLine("pulse");
            Thread.Sleep(1000);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to loop through a bunch of documents I have to put
I would like to count the length of a string with PHP. The string

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.