synchronized { }

Steven Schveighoffer schveiguy at yahoo.com
Thu Jun 26 13:12:48 PDT 2008


"Walter Bright" wrote
> 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?

Yeah, that seems not too useful, it only makes sense when writing functions 
that use global data.  In that case, it makes more sense to synchronize on 
the data instead of the code that accesses the data.  Otherwise, if you 
eventually have to access the data through other code, then you have to 
switch to synchronizing on the data anyways.  And if you forget to switch, 
then you now have a subtle bug :)  Better to force coders to think about why 
they are synchronizing and lock the appropriate object.

-Steve 





More information about the Digitalmars-d mailing list