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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:41:13+00:00 2026-05-29T10:41:13+00:00

Possible Duplicate: Are C# arrays thread safe? I have been programming C# for 10

  • 0

Possible Duplicate:
Are C# arrays thread safe?

I have been programming C# for 10 months now. I am now learning multi-threading and seems to be working nicely. I have multi-dimension array like

string[,] test = new string[5, 13]; 

I have the threads calling methods that end up saving their outputs to different coordinates inside the array above. without any one thread writing to the same location as another thread.

So thread1 might write to test[1,10] but no other thread will ever write to test[1,10]

My question is: I have read about using locks on objects like my array, do I have to worry at all about locks even though my threads might access to the test array at the same time but never write to the same coordinates(memory location)?

So far in my testing I have not had any issues, but if someone more seasoned than myself knows I could have issue then I’ll look into use locks.

  • 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-05-29T10:41:14+00:00Added an answer on May 29, 2026 at 10:41 am

    If you can ensure that no two threads will ever attempt to read or write to the same element then you have no need to do any locking, and if you do add locking you will slow down your code.

    You should however take the time to add comments as appropriate to explain that, (and possibly why) no threads ever access the same elements to avoid future problems that Jim Fell has mentioned in his answer.

    Update: Many of the other posters are continuing to suggest that locking be used merely as a safeguard against mistakes by future developers. To that end, it really depends on your application. If performance really isn’t much of an issue, then sure, go ahead and synchronize access to the elements.

    However, most of the time in which multiple threads are accessing a single array the reason that multiple threads exist is to perform parallel processing on large amounts of data in which performance is a significant concern. If it wasn’t much of a concern, then you could just use a single thread and be far more at ease about it not being messed up by others. In such high performance computing reliance on lock (in various forms) is, as a rule, minimized whenever possible. Synchronization through separation of data (meaning preventing them from ever reading/writing to the same memory locations) is far superior to using locks, when it is feasible.

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

Sidebar

Related Questions

Possible Duplicate: Are C# arrays thread safe? I have a program that is single-threaded
Possible duplicate : comparing-two-arrays I have two NSArray and I'd like to create a
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
Possible Duplicate: How do I use arrays in C++? I have no idea how
Possible Duplicate: Transposing multidimensional arrays in PHP I have three arrays: $a = (a1,
Possible Duplicate: deep copy NSMutableArray in Objective-C ? I have two arrays of length
Possible Duplicate: JavaScript arrays braces vs brackets I have a simple question that I
Possible Duplicate: Merge 2 Arrays and Sum the Values (Numeric Keys) I have two
Possible Duplicate: How to concatenate two arrays in Java? I have SET1 declared as
Possible Duplicate: How can you combine two arrays? I have variable $data1 that contains

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.