Connecting Tech Pros Worldwide Help | Site Map

Critical Section?

Ed S
Guest
 
Posts: n/a
#1: Nov 15 '05
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

Alvin Bruney
Guest
 
Posts: n/a
#2: Nov 15 '05

re: Critical Section?


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:eP69ac0nDHA.1672@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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
>[/color]


Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a
#3: Nov 15 '05

re: Critical Section?


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:eP69ac0nDHA.1672@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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
>[/color]


Closed Thread