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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:49:52+00:00 2026-06-18T22:49:52+00:00

I’m working on a Javascript reverse singly-linked list implementation. That is, a linked-list which

  • 0

I’m working on a Javascript reverse singly-linked list implementation. That is, a linked-list which instead of being referenced by a variable storing the head object, which contains a link to the next and so on, is stored in a tail variable referring to the list’s last node, each of which contains a link to the previous node. The gist of the implementation is below:

// A reversed linked list of the sequence 1, 2, 3
var tail = {
    value: 3,
    previous: {
        value: 2,
        previous: {
            value: 1,
            previous: null
        }
    }
};

The code to push a new node onto the end of this list (tail) looks like this:

tail = {
    value: 4,
    previous: tail
};

Here’s a demo: http://jsbin.com/ajixip/1/

The problem that I foresee with this push is a race condition that can occur between the retrieval of the curent value of tail and setting the new value.

Consider, for example, a user triggering an event, which pushes a new value to the tail of the list. Let’s call the time when the value of tail is retrieved and assigned to the key previous Time A and let’s call the point when tail is set to the new object Time B. If another push was made to the list between Time A and Time B, its previous would be the tail from Time A and assuming it would assign itself to tail after Time B, the first node push would be lost.

I’m puzzled by how such a race condition could be avoided. My initial thought was to implement a lock that prevented concurrent pushes, but there probably is some clever JS wizardry that avoids this. Any wizards care to share some of this magic?

Thanks!

  • 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-18T22:49:53+00:00Added an answer on June 18, 2026 at 10:49 pm

    Since Javascript is not multithreaded, you have no problem in the example you gave. This is, for all intents and purposes today, an atomic operation.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.