Hi,

I've seen several occurrences of synchronized (this) and synchronized (this.classinfo) in both druntime and phobos by now. I propose that we officially ban these patterns with extreme prejudice.

1) Locking on the object instance is a HORRIBLE IDEA. Anyone who happens to use the object for locking will most likely end up with a deadlock on their hands. 2) Locking on something as fundamental as type info means that any arbitrary part of the application could cause a deadlock by doing the same.

The solution to (1) is to simply use a Mutex internally (or an Object with synchronized statements), and for (2), to simply use private global objects.

(Now, regarding (1), you might argue that anyone who locks on an arbitrary object is doing it wrong, but you can't really blame them - it's frankly D's fault for allowing monitors on arbitrary objects, which is a horrible mess.)

Anyone against this?

--
Alex Rønne Petersen
[email protected]
http://lycus.org

Reply via email to