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

The Archive Base Latest Questions

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

Under what circumstances should each of the following synchronization objects be used? ReaderWriter lock

  • 0

Under what circumstances should each of the following synchronization objects be used?

  1. ReaderWriter lock
  2. Semaphore
  3. Mutex
  • 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:33:52+00:00Added an answer on May 11, 2026 at 3:33 pm
    • Since wait() will return once for each time post() is called, semaphores are a basic producer-consumer model – the simplest form of inter-thread message except maybe signals. They are used so one thread can tell another thread that something has happened that it’s interested in (and how many times), and for managing access to resources which can have at most a fixed finite number of users. They offer ordering guarantees needed for multi-threaded code.

    • Mutexes do what they say on the tin – ‘mutual exclusion’. They ensure that the right to access some resource is ‘held’ by only on thread at a time. This gives guarantees of atomicity and ordering needed for multi-threaded code. On most OSes, they also offer reasonably sophisticated waiter behaviour, in particular to avoid priority inversion.

    Note that a semaphore can easily be used to implement mutual exclusion, but that because a semaphore does not have an ‘owner thread’, you don’t get priority inversion avoidance with semaphores. So they are not suitable for all uses which require a ‘lock’.

    • ReaderWriter locks are an optimisation over mutexes, in cases where you will have a lot of contention, most accesses are read-only, and simultaneous reads are permissible for the data structure being protected. In such cases, exclusion is required only when a writer is involved – readers don’t need to be excluded from each other. To promote a reader to writer all other readers must finish (or abort and start waiting to retry if they also wish to become writers) before the writer lock is acquired. ReaderWriter locks are likely to be slower in cases where they aren’t faster, due to the additional book-keeping they do over mutexes.

    • Condition variables are for allowing threads to wait on certain facts or combinations of facts being true, where the condition in question is more complex than just ‘it has been poked’ as for semaphores, or ‘nobody else is using it’ for mutexes and the writer part of reader-writer locks, or ‘no writers are using it’ for the reader part of reader-writer locks. They are also used where the triggering condition is different for different waiting threads, but depends on some or all of the same state (memory locations or whatever).

    • Spin locks are for when you will be waiting a very short period of time (like a few cycles) on one processor or core, while another core (or piece of hardware such as an I/O bus) simultaneously does some work that you care about. In some cases they give a performance enhancement over other primitives such as semaphores or interrupts, but must be used with extreme care (since lock-free algorithms are difficult in modern memory models) and only when proven necessary (since bright ideas to avoid system primitives are often premature optimisation).

    Btw, these answers aren’t C# specific (hence for example the comment about ‘most OSes’). Richard makes the excellent point that in C# you should be using plain old locks where appropriate. I believe Monitors are a mutex/condition variable pair rolled into one object.

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

Sidebar

Related Questions

Are all of these equal? Under what circumstances should I choose each over the
Under what circumstances should I expect memcpys to outperform assignments on modern INTEL/AMD hardware?
I have a when in JBehave which under certain circumstances should throw an exception.
In .NET, under which circumstances should I use GC.SuppressFinalize() ? What advantage(s) does using
When setting up foreign keys in SQL Server, under what circumstances should you have
I am trying to figure out under what circumstances I should use weak (non-identifying)
A beginner question, bear with me: I'm just wondering under what circumstances one should
We've got a winforms LOB application, which under normal circumstances should be started from
I am wondering under what circumstances the following NHibernate code could fail: var session
Under normal circumstances, what should I expect the worse case scenario to be for

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.