synchronized { }
BCS
ao at pathlink.com
Thu Jun 26 16:42:32 PDT 2008
Reply to cemiller,
> I use it on occasion. It can be useful for singleton:
>
> if(!foo)
> {
> synchronized
> {
> if(!foo)
> foo = new Foo();
> }
> }
> return foo;
> especially useful because you don't need an object instance.
>
Hmmm. Slight variation on my last suggestion, Allow synchronized to take
any global symbol as the mutex
if(!foo)
{
synchronized(Foo) // global mutex on Foo
{
if(!foo)
foo = new Foo();
}
}
Or if you need more resolution:
class Foo
{
alias void single;
}
...
synchronized(Foo.single) // global mutex on Foo.single
...
More information about the Digitalmars-d
mailing list