basic concurrency

Sean Kelly sean at f4.ca
Tue Apr 18 16:25:00 PDT 2006


Tydr Schnubbis wrote:
> 
> When one thread executes a synchronized, piece of code, can another 
> thread execute another piece of synchronized code?  The way I read the D 
> docs, it can.  But how can this work if that's true?  That only one 
> thread can execute the 'get' method at any given time doesn't help if 
> another thread at the same time can execute another method that modifies 
> the same array.
> 
> And this syntax:
> synchronized void get(size_t i) {}
> 
> Does this allow get to be run only by one thread for all the objects of 
> the class, or one thread per object, like synchronized (this) {} does?

I believe 'synchronized' applied to an object method synchronized on 
that object, while 'synchronized' applied to a static method 
synchronizes on that type's ClassInfo object.  Finally, 'synchronized' 
in free functions synchronizes on the global monitor.  Does that help?


Sean



More information about the Digitalmars-d-learn mailing list