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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:43:19+00:00 2026-06-17T05:43:19+00:00

After a sking this question , I still have a question. I got both

  • 0

After asking this question , I still have a question.

I got both excellent answers but I’m still having a trouble finding how could this actually be occur: ( how could a fault situation can occur) :

I will start with an example :

public void Do(string [] g)
{
   g=null;     //<========
}

void Main()
{
    var t=new string[3];
    t[0]="1";   t[1]="1";   t[2]="1";
    Do( t);
    Console.WriteLine ( t.Length);
}

the notated line can be execute in a different thread but each thread has its own g variable !
(and please remember that I can’t add items to an arrray. cause array length is created at creation)

No matter what will I do with the function Do – (no matter in what thread) , the Console.Writeline result will always be 3 ( unless using ref).

so lets see the real code :

    public static string Concat(params string[] values)
  #1  {
  #2      if (values == null)
  #3       {
  #4            throw new ArgumentNullException("values");
  #5       }
  #6        int totalLength = 0;
  #7        string[] strArray = new string[values.Length];
  #8        for (int i = 0; i < values.Length; i++)
  #9          {
  #10            string str = values[i];
  #11            strArray[i] = (str == null) ? Empty : str;
  #12            totalLength += strArray[i].Length;
  #13            if (totalLength < 0)
  #14            {
  #15                throw new OutOfMemoryException();
  #16            }
  #17         }
  #18        return ConcatArray(strArray, totalLength);
  #19   }

My saying is : once I’m on #1 , in thread X , this thread will forever will have array with length 3.

If another thread wants to destroy/change the array length ( which I cant understand how , cause the array has fixed length , all he can do is making it null) – it will have a different copy of pointer address.

I must be missing something here.

  • What am I missing ?

  • what is the code which other thread could execute which will cause an error ?(assuming we don’t copy the array).

  • 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-17T05:43:21+00:00Added an answer on June 17, 2026 at 5:43 am

    what is the code which other thread could execute which will cause an error ?

    string[] data = { "1", "2", "3" };
    ThreadPool.QueueUserWorkItem( () => { data[0] = "one"; } );
    string total = String.Concat(data);
    

    Without the intermediate array there would be a race condition, the Thread could change data[0] after its length was added to totalLength but before the (presumably unsafe) call to ConcatArray(). The low-level method would then copy 5 chars to a buffer of size 3.

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

Sidebar

Related Questions

After deploying WCF server (svc) on my Server, I have got this message when
I have successfully done this before but now after running the program numerous times
Bit of a weird title but here what i got. I have found this
This is no doubt a simple question for expert 'swingers' but after some research
I hope this question is SO worthy, but I'll give it a try... I
I'm trying to learn Java so sorry if this is a stupid question, but
This might be duplicate of this and this question . I have a java
After discovering about Javascript namespaces, I tried to implement them but I run into
After some time researching and trying different things I still cannot get my @ExceptionHandler
After a long search I'm still confused about it although I found some related

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.