A monitor for every object

Kagamin spam at here.lot
Fri Feb 4 06:23:57 PST 2011


bearophile Wrote:

> a certain programming language which starts with "J" that saw fit to make EVERY object have its very own monitor....<
> So is the design choice of copying this part of the Java design inside D good? I'd like opinions on this topic.

C# has this design too, but locking a common object directly is not used. C# used to create separate object for locking, the property to access it being called SyncRoot. It's implementation is a usual combination of new object() and CompareExchange.

http://msdn.microsoft.com/en-us/library/system.collections.icollection.syncroot.aspx

I don't feel the need for locking functionality in Object, this is usually a major design decision for a couple of classes - even in a large project. After all, after this design decision you should also carefully implement the locking in the code using the object, this will take some time, so it can't be a light-minded decision.


More information about the Digitalmars-d mailing list