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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:08:04+00:00 2026-05-26T16:08:04+00:00

Does the ordered locking pattern prevent deadlocks when used with a ReaderWriterLock (or ReaderWriterLockSlim)?

  • 0

Does the ordered locking pattern prevent deadlocks when used with a ReaderWriterLock (or ReaderWriterLockSlim)?

Clearly the pattern prevents deadlocks with a mutex. Does it still prevent deadlocks if I am locking several resources with ((N resources with read locks) and (1 or 2 resources with write locks)).

For example: (Bold numbers represent resources with write locks)

1 2 3 4 5

2 3 4

1 4 5

  • 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-26T16:08:04+00:00Added an answer on May 26, 2026 at 4:08 pm

    tl;dr Resource ordering prevents deadlock for reader-writer locks too.

    Long answer:

    Draw a wait-for graph like this:

    First draw a vertex for all the resources from left to right in the
    prescribed order.

    Then, for each process, waiting for a resource, draw a vertex,
    immediately preceding the vertex of the waited for resource.
    If a process is not waiting on any resources, draw a vertex
    on the far right, after all the resource vertices.

    Then draw an edge from each process to the resource on which that
    process is waiting and draw an edge from each resource to the
    process, which is currently holding that resource.

    Consider each edge on the graph. There are two cases:

    • the edge is Pi -> Ri, i.e. from a process to a resource. Since each
      process is waiting on only one resource and we have drawn the
      process’ vertex immediately to the left of the resource it is
      waiting for, then the edge is from left to right.

    • the edge is Ri -> Pj, i.e. from a resource to a process. If Pj is
      not waiting to any resource, then its vertex is on the right of
      all the resources, therefore the edge is from left to right. If Pj
      is waiting to Rk, then i < k, because processes acquire resources in
      order. If i < k, then Ri is on the left of Rk, and Pj is
      immediately on the left of Rk (since we have drawn the grapgh that way),
      hence Ri is on the left of Pj, therefore the edge is again left to
      right.

    Since all the edges of the graph drawn this way are from left to
    right, then we have constructed a topological sorting of the graph,
    hence the graph has no cycles, hence a deadlock cannot occur.

    Note that what matters is the fact that a process waits, not why it
    waits. Thus, it does no matter whether it waits for a mutex,
    read-write lock, semaphore or whatever – this strategy for deadlock
    prevention works for all.

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

Sidebar

Related Questions

Does anyone have a good algorithm for taking an ordered list of integers, i.e.:
Does anyone remember the XMP tag? What was it used for and why was
Does anybody know any good resources for learning how to program CIL with in-depth
Does anyone know how to return an ordered list of strings with null values
Does native built-in python dict guarantee that the keys() and values() lists are ordered
I currently have the following html which does not show the ordered list properly
Does the Entity Framework 4 have ordered collections? For example my Order has a
What does this mean: the value must be an ordered set of unique space-separated
Does there exist an algorithm which, given an ordered list of symbols {a1, a2,
I know certain commends need the hashmap / dictionary to be ordered, but does

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.