Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Thread Safe Class
Message
General information
Forum:
ASP.NET
Category:
Class design
Title:
Thread Safe Class
Miscellaneous
Thread ID:
01417234
Message ID:
01417234
Views:
120
This question is a follow up on my earlier Singleton question...

How do you make a class Thread-Safe?

Would this class be both thread-safe and a singleton?
class MyClass
{
    private static readonly object _lockobj = new object();

    private static MyClass instance = null;
    public static MyClass Instance
    {
        get
        {
            if (instance == null)
                instance = new MyClass();

            return instance;
        }
    }

    public MyClass()
    {
        lock (_lockobj) ;
    }
}
Since the class is a singleton, and by getting a lock in the CTOR, is it now thread-safe, assuming I do
MyClass class = MyClass.Instance.
Thanks
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Next
Reply
Map
View

Click here to load this message in the networking platform