Connecting Tech Pros Worldwide Help | Site Map

Critical Section?

  #1  
Old November 15th, 2005, 02:29 PM
Ed S
Guest
 
Posts: n/a
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

  #2  
Old November 15th, 2005, 02:29 PM
Alvin Bruney
Guest
 
Posts: n/a

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]


  #3  
Old November 15th, 2005, 02:29 PM
Jay B. Harlow [MVP - Outlook]
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firing events from within a critical section =?Utf-8?B?VmFubmk=?= answers 5 September 7th, 2007 01:25 AM
Critical Section in a Webservice? Harry Whitehouse answers 3 May 20th, 2006 12:05 AM
Critical section in WebForms Christian answers 2 November 18th, 2005 08:05 PM
mutex? protecting global data/critical section Brian Alexander answers 2 July 18th, 2005 03:45 AM