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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:49:19+00:00 2026-06-01T08:49:19+00:00

I’m using this approach to store data in a global array hosting an http

  • 0

I’m using this approach to store data in a global array hosting an http server where certain requests will manipulate the global array.

I’m kind of worried about running into threading issues with certain operations — mainly push and splice. I imagine if one request has me iterating over the array and removing items based on a conditional, while another request has me calling .push() on the array that I’ll run into issues. Can anyone confirm this?

I mostly write in C# where even a simple increment isn’t thread safe (launching 25 threads that do i++, won’t guarantee that i == 25 after all is said and done).

Update:

I’ve written 5 examples to demonstrate what I’m talking about. Test 1 and Test 3 work fine. Test 2 fails, because of well… what normally would be called threading issues (whether they are actual CPU threads or not). Test 4 and 5, when run in parallel seem to work (meaning they don’t have collision problems like Test 2).

http://pastebin.com/HcJHTDFY

I’m using ApacheBench to test, making 1000 parallel requests.

This leads me to believe that Test 1 and Test 3 work fine because nodejs won’t execute more than 1 instance of the app.get('/test3'...) callback in parallel javascript function in parallel (blocking?). As soon as you implement a setInterval/setTimeout, it frees up nodejs to execute another instance of the callback (non-blocking?).

I’m really just trying to understand what the heck non-blocking I/O model really means. Does it mean that “hey it’s possible to do non-blocking with setTimeout and setInterval if you need non-blocking, otherwise we’re going to block any other outer-level functions from being run until we exhaust the function we’re on”? I feel it’s imperative to know this so that I don’t get myself into trouble thinking I could implement something like /test2 and be totally safe.

Also if I’m trying to be non-blocking with my callbacks, should I really be calling setTimeout(code, 1)? Or is there a better way?

  • 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-01T08:49:20+00:00Added an answer on June 1, 2026 at 8:49 am

    All are thread safe.

    There are no threads, JavaScript is single threaded, it’s impossible for two javascript statements to run at the same time.

    As an aside, you shouldn’t be using globals anyway because globals are evil

    Edit:

    Test 2 fails because you’re using asynchronous callbacks, which means control goes back to node and it can handle more requests. This creates race conditions as seen.

    In node, anything that’s not asynchronous blocks. The only asynchronous things you have are setTimeout/setInterval/process.nextTick and any asynchronous IO operations.

    One shouldn’t manually make computation asychronous. One should just avoid doing too much computation.

    I’ve written an article about What it means to be non-blocking

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,

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.