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 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

Ask A Question

Stats

  • Questions 222k
  • Answers 222k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Before the interpreter or compiler can build a parse tree,… May 13, 2026 at 12:24 am
  • Editorial Team
    Editorial Team added an answer Have a look at this property of the TCPClient Object… May 13, 2026 at 12:24 am
  • Editorial Team
    Editorial Team added an answer You need to define a function that performs whatever rounding… May 13, 2026 at 12:24 am

Related Questions

I'm trying to write a regex that will match everything BUT an apostrophe that
Hi I'm trying to get some practice with Linked Lists. I Defined an Object
HI I'm trying to put a textbox to search in a listBox. I have
What is the simplest way to write a timer in C/C++? Hi, What is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.