More synchronized ideas

Jason House jason.james.house at gmail.com
Mon Jun 4 06:15:57 PDT 2012


On Monday, 4 June 2012 at 11:17:45 UTC, Michel Fortin wrote:
> After trying to make sense of the thread "synchronized 
> (this[.classinfo]) in druntime and phobos", I had to write my 
> opinion on all this somewhere that wouldn't be instantly lost 
> in a bazilion of posts. It turned out into something quite 
> elaborate.
>
> <http://michelf.com/weblog/2012/mutex-synchonization-in-d/>

The example about current D seems a bit lacking. You change 
behavior because it's easy to code a different way. If you really 
want to use synchronized classes, then you should have two of 
them. The map can be in one synchronized class and the counters 
can be in another. the main class in the example would simply 
call methods on the synchronized objects.

That being said, I've never used synchronized classes in my 
multithreaded D1/D2 code. I used Tango's Mutexes and Conditions. 
They're more flexible. That being said, I think the use of a 
synchronized class for your counters is perfectly reasonable and 
would simplify validating the code for correctness.


More information about the Digitalmars-d mailing list