basic concurrency

Tydr Schnubbis fake at address.dude
Tue Apr 18 18:00:17 PDT 2006


Sean Kelly wrote:
> 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?
> 
It answers the second question I think, but the first one is more 
important for me to understand the answer to.  But thanks anyway. :)



More information about the Digitalmars-d-learn mailing list