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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:21:26+00:00 2026-05-16T12:21:26+00:00

My question is why does this line – ThreadTest tt = new ThreadTest(); in

  • 0

My question is why does this line – ThreadTest tt = new ThreadTest(); in below example create a common instance not a separate instance. Please advise, thanks!

class ThreadTest
{
  bool done;

  static void Main()
  {
    ThreadTest tt = new ThreadTest();   // Create a common instance
    new Thread (tt.Go).Start();
    tt.Go();
  }

  // Note that Go is now an instance method
  void Go() 
  {
     if (!done) { done = true; Console.WriteLine ("Done"); }
  }
}

EDIT:
The example is from http://www.albahari.com/threading/#_Introduction which demonstrates how to share data between threads.

EDIT2:
My question is exactly why “the instance is common to both threads”

  • 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-16T12:21:27+00:00Added an answer on May 16, 2026 at 12:21 pm

    It is unclear what you mean by “common instance”, but the constructor definitely creates a new instance. The Go method is executed twice, once in the new thread and once in the main thread.

    Maybe what the author of the code meant is that the instance is common to both threads, because both threads call the Go method on the same instance.

    The inside of the Go method has a race condition. It may unpredictably print “Done” twice.

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

Sidebar

Related Questions

EDIT (Side Question) Can someone please explain what this line does? eval website=\${$#} The
(This question does not rely on a specific IoC framework, so the interfaces and
I've spotted this question: Does Microsoft SkyDrive have an API? But not having an
Question from the one interview. Please explain what does this C++ code mean: void
Quick and silly jQuery selector question. Why this does not work : jsFiddle demo
The manual does not answer this question : it says the name of the
everybody! I have a simple question. What does this line do? trap exec 1>&6
This is part of a code. The question is, does this line $(#b_facetNewChild).button().click(function(){ means
Why does this line of code cause Excel not to exit? Excel.Range range =
Simple question for you guys. What does this line replace? .replace(/ /g,'+')

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.