On 5/30/12 9:43 AM, Regan Heath wrote:
On Wed, 30 May 2012 17:00:43 +0100, Andrei Alexandrescu
<seewebsiteforem...@erdani.org> wrote:

On 5/30/12 5:32 AM, Regan Heath wrote:
On Wed, 30 May 2012 10:21:00 +0100, deadalnix <deadal...@gmail.com>
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.

Can you call pass them to a synchronized statement? i.e.

TDPLStyleSynchClass a = new TDPLStyleSynchClass();
synchronized(a) {
}

Yes. Well I recommend acquiring the text! :o)

... because, if you can, then you're exposing the mutex.

No.

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.

True. But in my Example 1

Your example 1 should not compile.

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

Is there anywhere I can see this online? (for free :p)

http://goo.gl/ZhPM2

The implicit mutexes used by synchronized classes are recursive.

:) why would you want anything else.

Efficiency.


Andrei

Reply via email to