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

  • Home
  • SEARCH
  • 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 6759553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:57:23+00:00 2026-05-26T13:57:23+00:00

EDIT: Ok, it works now. I don’t know exactly what was the worst problem,

  • 0

EDIT: Ok, it works now. I don’t know exactly what was the worst problem, but i haven’t done some locking which was needed to avoid race conditions. Also i added the “volatile” key-word to the deklaration of the instance variable of the singleton.

if i have some threads running and in one thread i access a singleton (which was maybe created in another thread), i get a fresh “singleton” in terms of that the constructor of the singleton is called for every thread who access it in his memory space the first time? Have i understood this right?

The problem is in my application i have a singleton created by the main thread. If i then call Singleton.Instance.somemethod(…) i get always null pointer exceptions or empty lists, even if the lists were created and filled in the main thread?

Is there a way to handle that problem, so that i can use the same instance of the singleton in all threads running? Some way of synchronizing the whole instance?

Thank you.

EDIT: Sorry lacking some really important information. I am using C# and the .NET Framework 4.0 under Visual Studio 2010 Professional.

I create the Singleton this way:

 static readonly object _padlock = new object();

    public static StaticAnalyzer Instance
    {
        get
        {
            lock (_padlock)
            {
                if (_instance == null)
                {
                    _instance = new StaticAnalyzer();
                }
                return _instance;
            }
        }
    }

In the background every thread has its own virtual memory space or not? So if i create the singleton in the main thread and then in create some worker threads with the task.factory and the worker threads call the instance, why does they get the real singleton? because of the static keyword?

  • 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-26T13:57:24+00:00Added an answer on May 26, 2026 at 1:57 pm

    No, a singleton (if implemented correctly) will be just one for all the threads. Like System.DBNull. Otherwise it’s not a singleton. You must have a mistake in your code somewhere.

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

Sidebar

Related Questions

EDIT AGAIN: someone posted the solution, but it has a wierd x I don't
I'm writing a program in c# for Windows7 that works very fine... But now
EDIT: this works, but not sure why? $('button').each(function() { $(this).bind( click, function() { alert($(this).val());
This works: Entities.WorkOrderSet.Where(MyCustomMethod); This does not: Entities.WorkOrderSet.Where(o => MyCustomMethod(o)); ( [Edit] Even without new
I use edit-in-place plugin: http://arashkarimzadeh.com/jquery/7-editable-jquery-plugin.html I't works Great! I just need something to check
EDIT: Scotty2012 and David Morton's answers don't work for me so I have put
Edit: This question was written in 2008, which was like 3 internet ages ago.
[Edit: don't try to understand the whole thing and don't waste your time to
I created this to simply explain my problem. It is of some list items
**EDIT: There are several options below that would work. Please vote/comment according to your

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.