synchronized { }
Lionello Lunesu
lionello at lunesu.remove.com
Thu Jun 26 18:02:26 PDT 2008
"Walter Bright" <newshound1 at digitalmars.com> wrote in message
news:g3uqph$2s3n$1 at digitalmars.com...
> Right now, if you use a synchronized statement with no argument, it will
> sync on a mutex unique to that statement.
>
> Does anyone write threading code that depends on this behavior?
Never understood that one, so: no.
But I do think there's a place for synchronized { }: memory barrier.
IIRC a mutex always implies a memory barrier anyway. synchronized without
argument could only create a memory barrier. This could then be used to
achieve what the Interlocked* functions in Win32 do. It's such a basic
operation that I think it warrants a language construct.
static int b;//some global
int a;//local
// native cross-platform InterlockedIncrement
synchronized
{
a = b++;
}
I should note however that I'm currently having a hard-time implementing
some multi-threaded algorithms.. I probably don't know enough about MT to be
messing with it :S
L.
More information about the Digitalmars-d
mailing list