468,535 Members | 1,848 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,535 developers. It's quick & easy.

Critical Section?

HiAll,

What would you suggest I use if I want to protect the creation of a
singleton - in the instance() static method. In C++, I'd use a critical
section.

Thanks,

--Ed

Nov 15 '05 #1
2 19360
say
lock(this)
{
create singleton here
}

Locking on this is bad though because some other thread could conceivably
lock on this creating a deadlock of sorts. But that will give you roughly
the equivalent of a critical section.
--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Ed S" <esinek.mapson-a-t-mapson.summation.com> wrote in message
news:eP**************@TK2MSFTNGP09.phx.gbl...
HiAll,

What would you suggest I use if I want to protect the creation of a
singleton - in the instance() static method. In C++, I'd use a critical
section.

Thanks,

--Ed

Nov 15 '05 #2
Ed,
Here is a write up on how to write a Singleton in C#, complete with making
it thread safe.

http://www.yoda.arachsys.com/csharp/singleton.html

Hope this helps
Jay

"Ed S" <esinek.mapson-a-t-mapson.summation.com> wrote in message
news:eP**************@TK2MSFTNGP09.phx.gbl...
HiAll,

What would you suggest I use if I want to protect the creation of a
singleton - in the instance() static method. In C++, I'd use a critical
section.

Thanks,

--Ed

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Brian Alexander | last post: by
2 posts views Thread by Xarky | last post: by
7 posts views Thread by Piotrek Stachowicz | last post: by
6 posts views Thread by MPH Computers | last post: by
2 posts views Thread by Christian | last post: by
1 post views Thread by James Hunter Ross | last post: by
3 posts views Thread by Harry Whitehouse | last post: by
5 posts views Thread by =?Utf-8?B?VmFubmk=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.