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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:21:24+00:00 2026-06-15T07:21:24+00:00

After reading Jon Skeet article , and this article from msdn , I still

  • 0

After reading Jon Skeet article , and this article from msdn , I still have a question

Let’s say I have this code :

  MyPerson mp = new MyPerson(); //Field

  int g=0; //Field

  public void DoWork ()
   {
      int i;
      MyPerson mp2 = new MyPerson();  
      ...
   }

Now let’s say I have 2 threads. which runs DoWork. ( let’s ignore for now , race conditions)

  • Will they both see the same g or each thread will have its own item ? ? ( value )

  • Will they both see the same mp or each thread will have its own item ?? ( instance )

  • Will they both see the same i or each thread will have its own item ? ( value )

  • Will they both see the same mp2 or each thread will have its own item ? ( instance )

  • if they both see the same , why would I need static ?

I’ve searched a lot about this topic , and couldn’t find any article which states : Different Threads ,ref types and value types… )

  • 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-15T07:21:26+00:00Added an answer on June 15, 2026 at 7:21 am

    Neither thread simply “runs DoWork“; they run DoWork on a particular object. If the two threads are created targeting different instances, then mp and g will be completely separate fields. If the two threads are created targeting the same instance, then mp and g will be shared but it is not guaranteed that the threads will see changes made by the other thread unless you use synchronization or volatile access.

    For example:

    var obj = new SomeObject();
    Thread thread1 = new Thread(obj.DoWork);
    Thread thread2 = new Thread(obj.DoWork); // clearly targeting the same instance
    

    vs

    var obj = new SomeObject();
    Thread thread1 = new Thread(obj.DoWork);
    obj = new SomeObject();
    Thread thread2 = new Thread(obj.DoWork); // targeting a different instance
    

    The local variables i and mp2 are strictly specific to each thread.

    Additional note: even if they are separate fields/locals, if some of the code in the ... later reassigns mp or mp2 to refer to the same object, then they will be squabbling over the same object; the same synchronization / volatile rules will apply.

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

Sidebar

Related Questions

After reading this article, it makes sense to rebase to gather changes from the
After reading this nice article (The Care and Feeding of Pre-Compiled Headers), I have
After reading Odd query expressions by Jon Skeet, I tried the code below. I
After reading answer to this question: Make "make" default to "make -j 8" I
After reading MSDN-XAML Namespaces and MSDN-Understanding XAML Namespaces , I still do not understand
After reading this question, I need to clear up some things. IQueryable<Customer> custs =
After reading similar questions with many variants, I'm still stuck on this issue. Here's
After becoming more engaged with training new engineers as well as reading Jon Skeet's
After reading many times this question and its accepted answer How to execute a
After reading, this question . I figured I need to look over my structure

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.