On 29-05-2012 23:38, Andrei Alexandrescu wrote:
On 5/29/12 5:26 AM, Alex Rønne Petersen wrote:
Generalized object monitors is the worst idea in programming language
and virtual machine design, ever.

I think that's an exaggeration. Care to elaborate a bit?

Andrei


1) You waste an entire word of memory in *every single object you ever create*. And for the majority of objects, this word will always be zero/null. Not to mention that when you do allocate a monitor, you also get the actual memory of that monitor in addition. 2) Anyone can lock on any object meaning it's near impossible to see where a deadlock might come from.
3) Encapsulation is completely broken as a result of (2).
4) There's a whole bunch of runtime and GC plumbing (which is even broken in druntime right now) to support object monitors. To fix this entire mess, we'd need weak references. 5) This whole object monitor model goes against our "thread-local by default" model. Synchronization is evil and should be explicit with core.sync.mutex.

--
Alex Rønne Petersen
a...@lycus.org
http://lycus.org

Reply via email to