synchronized confusion...

estewh estewh at gmail.com
Mon Apr 15 23:06:54 PDT 2013


Hi All,

I have this bit of code like this:

shared bool varInitialized = false;
bool initVar() {
    bool ret;
    synchronized { ret = varInitialized;}
    return ret;
}

I know there are atomics and I am using them but I am curious 
about the above code. It compiles but I have no idea how safe it 
is.

Reading TDPL I got the impression synchronized works only for 
entire classes. If so why does the above compile and is it thread 
safe?

Thanks for any help

Cheers,
Stewart



More information about the Digitalmars-d-learn mailing list