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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:31:44+00:00 2026-06-12T04:31:44+00:00

I will try to make this question as generic as possible, but I will

  • 0

I will try to make this question as generic as possible, but I will give a brief introduction to my actual problem –

I am trying to implement a concurrent skiplist for a priority queue. Each ‘node’, has a value, and an array of ‘forward’ nodes, where node.forward[i] represents the next node on the i-th level of the skiplist. For write access (i.e. insertions and deletions), I use a Spinlock (still to determine if that is the best lock to use)

My question is essentially, when I need a read access for a traversal,

node = node.forward[i]

What kind of thread safety do I need around something like this? If another thread is modifying node.forward[i] at exactly the same time that I read (with no current locking mechanism for read), what can happen here?

My initial thought is to have a ReaderWriterLockSLim on the getter and setter of the indexer for Forward. Will there be too much unnecessary locking in this scenario?

Edit: Or would it be best to instead use a Interlocked.Exchange for all of my reads?

  • 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-12T04:31:45+00:00Added an answer on June 12, 2026 at 4:31 am

    If another thread is modifying node.forward[i] at exactly the same time that I read (with no current locking mechanism for read), what can happen here?

    It really depends on the implementation. It’s possible to use Interlocked.Exchange when setting “forward” in a way that can prevent the references from being invalid (as it can make the “set” atomic), but there is no guarantee of which reference you’d get on read. However, with a naive implementation, anything can happen, including getting bad data.

    My initial thought is to have a ReaderWriterLockSLim on the getter and setter of the indexer for Forward.

    This is likely to be a good place to start. It will be fairly easy to make a properly synchronized collection using a ReaderWriterLockSlim, and functional is always the first priority.

    This would likely be a good starting point.

    Will there be too much unnecessary locking in this scenario?

    There’s no way to know without seeing how you implement it, and more importantly, how it’s goign to be used. Depending on your usage, you can profile and look for optimization opportunities if necessary at that point.

    On a side note – you might want to reconsider using node.Forward[i] as opposed to more of a “linked list” approach here. Any access to Forward[i] is likely to require a fair bit of synchronization to iterate through the skip list i steps, all of which will need some synchronization to prevent errors if there are concurrent writes anywhere between node and i elements beyond node. If you only look ahead one step, you can (potentially) reduce the amount of synchronization required.

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

Sidebar

Related Questions

I will try to make this as straight forward as possible. This question does
I will try to make this as clear as I can, but if you
Not sure how you'll take this question but... Whenever I try to make my
I will try to make my question sound as unconfusing as possible. I appologize
I know this sounds like a subjective answer, but I will try to make
I'm fairly new to C# but I will try to make this quick! ;)
Most of you will probably label this is a very generic question, but still,
I don't want to create a vague question so I will try to make
I will try and word this question the best I can, for it is
I will try to keep this as simple as possible. I have a rather

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.