On 5/30/12 5:32 AM, Regan Heath wrote:
On Wed, 30 May 2012 10:21:00 +0100, deadalnix <[email protected]> wrote:
You don't want to synchronize on ANY object. You want to synchronize
on explicit mutexes.

+1 .. this is the key point/issue.

TDPL's design only allows for entire synchronized classes (not separate synchronized and unsynchronized methods), which pair mutexes with the data they protect. This is more restrictive than exposing mutexes, but in a good way. We use such a library artifact in C++ at Facebook all the time, to great success.

People shouldn't create designs that have synchronized classes referring to one another naively. Designing with mutexes (explicit or implicit) will always create the possibility of deadlock, so examples how that could happen are easy to come across.

TDPL improves on deadlocks by introducing synchronized statements with more than one argument, see 13.15.

The implicit mutexes used by synchronized classes are recursive.


Andrei

Reply via email to