Boost logo

Boost :

From: Andrew J Bromage (ajb_at_[hidden])
Date: 2002-08-07 18:54:56

G'day all.

On Wed, Aug 07, 2002 at 01:44:02PM +0300, Peter Dimov wrote:

> Are you sure that you want that.

Well, anything which has equivalent semantics and more importantly,
equivalent contention-avoidance would do. For example, a "one shot
mutex" which only succeeded in locking the first time you tried it
would do the trick, though this would probably have different
exception semantics.

> Your "once" object is dynamically initialized. It is pretty much the same as
> a boost::mutex; there is no reason for it to be more efficient than a mutex.

The same argument could be made against lightweight mutexes, or atomic
counters. Admittedly boost doesn't currently expose atomic_count as
a supported interface (arguably a good thing), but still, it's there
for a reason.

On all platforms that I'm aware of, releasing a mutex lock costs at
least one system call. On many platforms, even obtaining an
uncontested lock costs a system call. This is a heavyweight
solution for a lightweight problem: protecting a read of a single flag
which is only going to be mutated once in its lifetime. I can see
this causing problems in times of heavy concurrency.

Incidentally, I do have no problem to falling back to a single
boost::mutex in platforms where there's no better way.

Andrew Bromage

Boost list run by bdawes at, gregod at, cpdaniel at, john at