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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:15:02+00:00 2026-05-11T06:15:02+00:00

Hi im trying to write a lockless list i got the adding part working

  • 0

Hi im trying to write a lockless list i got the adding part working it think but the code that extracts objects from the list does not work to good 🙁

Well the list is not a normal list.. i have the Interface IWorkItem

interface IWorkItem {     DateTime ExecuteTime { get; }     bool Cancelled { get; }     void Execute(DateTime now); } 

and well i have a list where i can add this 😛 and the idear is when i run Get(); on the list it should loop it until it finds a IWorkItem that

If (item.ExecuteTime < DateTime.Now) 

and remove it from the list and return it.. i have ran tests with many threads on my dual core cpu and it seems that Add works never failed so far but the Get function looses some workitems some where i have no idear whats wrong…..

ps if i get this working any one is free to use the code 🙂 well you are any way but i dont se the point when its bugged 😛

The code is here http://www.easy-share.com/1903474734/LinkedList.zip and if you try to run it you will see that it will some times not be able to get as many workitems as it did put in the list…

Edit: I have got a lockless list working it was faster than using the lock(obj) statment but i have a lock object that uses Interlocked that was still outpreforming the lockless list, im going to try to make a lockless arraylist and se if i get the same results there when im done ill upload the result here..

  • 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-11T06:15:02+00:00Added an answer on May 11, 2026 at 6:15 am

    The problem is your algorithm: Consider this sequence of events:

    Thread 1 calls list.Add(workItem1), which completes fully.

    Status is:

    first=workItem1, workItem1.next = null 

    Then thread 1 calls list.Add(workItem2) and reaches the spot right before the second Replace (where you have the comment ‘//lets try’).

    Status is:

    first=workItem1, workItem1.next = null, nextItem=workItem1 

    At this point thread 2 takes over and calls list.Get(). Assume workItem1‘s executionTime is now, so the call succeeds and returns workItem1.

    After this status is:

    first = null, workItem1.next = null 

    (and in the other thread, nextItem is still workItem1).

    Now we get back to the first thread, and it completes the Add() by setting workItem1.next:=workItem2.

    If we call list.Get() now, we will get null, even though the Add() completed successfully.

    You should probably look up a real peer-reviewed lock-free linked list algorithm. I think the standard one is this by John Valois. There is a C++ implementation here. This article on lock-free priority queues might also be of use.

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

Sidebar

Related Questions

Trying to write a python application that downloads images from an RSS feed, and
Trying to write a GLOBAL CBT HOOK, this is My code, but my hooking
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
I'm trying to write a regex function that will identify and replace a single
I'm trying to write a blog post which includes a code segment inside a
I'm trying to write a custom WPF ValidationRule to enforce that a certain property
I'm trying to write a stored procedure to select employees who have birthdays that
I'm trying to write a page that calls PHP that's stored in a MySQL
I'm trying to write a Wordpress plug-in that automatically posts a blog post at
I am trying write a SQL query that filters a gridview by the fields

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.