SharpCrafters Forum – singleton

SharpCrafters Support Forum

        


singleton Expand / Collapse
Author
Message
Posted 3/17/2008 12:23:24 PM


blahetal

Community Member
Hi, is your implementation of Singleton thread-safe?
Post #3288
Posted 3/17/2008 2:20:58 PM


Ignacio Vivona

Community Member
The current implementation use the static constructor to initialize the static variable that holds the singleton. Static constructors are called by the run-time at most once. So i believe they are thread-safe, but there is a lot to read with a simple google search about the issue. If someone can say a word about this is welcome to do so.

Cheers.
Ignacio
Post #3289
Posted 3/17/2008 2:34:36 PM


blahetal

Community Member
Ok, I found this article
http://www.yoda.arachsys.com/csharp/singleton.html

and from your post I understand that you use the first method (to create a Singleton) that is described in the article above. Well, and there is written that using pure static constructors (without any synchronization mechanism) is not thread safe. Could you check it.
Post #3290
Posted 3/17/2008 3:50:29 PM


Ignacio Vivona

Community Member
I have read that, but what i do is close to the fourth form. I do the initialization in the static constructor, the accessor only retrieves the instance.

Ignacio.
Post #3291
« Prev Topic | Next Topic »


All times are GMT +1:00, Time now is 9:40pm

Powered By InstantForum.NET v4.1.4 © 2010
Execution: 0.128. 9 queries. Compression Disabled.