|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-08-24 10:36:51
Howard Hinnant wrote:
> On Aug 23, 2007, at 10:35 AM, Peter Dimov wrote:
>
>> On reflection though, I'll change the constructor from
>>
>> explicit condition( Mutex * pm = 0 );
>>
>> to
>>
>> explicit condition( Mutex * pm );
>>
>> as it's too easy to accidentally disable checking by not including
>> the condition in the member init list.
>
> Doesn't this remove goal 2?
>
> 2. The freedom to dynamically associate mutexes with condition
> variables.
No, condition( 0 ) still works as before, it's just not a default
constructor. The problem is that in:
class X
{
mutex mx_;
condition cn_;
public:
X() {}
};
the author of X may have accidentally omitted the initialization of cn_.
Without a default constructor, this doesn't compile and one needs to
explicitly choose between
X(): cn_( &mx_ ) {}
and
X(): cn_( 0 ) {} // no checking
The compromise where a default-constructed (checked) condition is
automatically associated with the mutex the first time wait is called
doesn't help if one consistently uses wait with the wrong mutex (as could
happen if there is a single wait call in the code - not unusual).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk