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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:23:36+00:00 2026-06-01T22:23:36+00:00

Please bear with me on this as I’m new to this. I have an

  • 0

Please bear with me on this as I’m new to this.

I have an array and two threads.

First thread appends new elements to the array when required

myArray ~= newArray;

Second thread removes elements from the array when required:

extractedArray = myArray[0..10];
myArray = myArray[10..myArray.length()];

Is this thread safe?
What happens when the two threads interact on the array at the exact same time?

  • 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-01T22:23:38+00:00Added an answer on June 1, 2026 at 10:23 pm

    this is not thread safe

    this has the classic lost update race:

    appending means examening the array to see if it can expand in-place, if not it needs to make a (O(n) time) copy while the copy is busy the other thread can slice of a piece and when the copy is done that piece will return

    you should look into using a linked list implementation which are easier to make thread safe

    Java’s ConcurrentLinkedQueue uses the list described here for it’s implementation and you can implement it with the core.atomic.cas() in the standard library

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

Sidebar

Related Questions

This is kinda confusing so please bear with me. I have an array (listOfStates)
I am new to this, so please bear with me... If we have the
I'm kind of new to this so please bear with me. I have a
This is all new to me to please bear with me! I have a
I'm a Java-beginner, so please bear with this one. I have a class: class
Please bear with me if this isn't clear, this is my first posting here.
Please bear in mind that I'm totally new to Rails when answering this.My question
I am new to bash so please bear with me if this is a
I am new to git and if this ques is simple then please bear
This is my first post on Stack, so please bear with me if I

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.