Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-08-06 08:21:27

From: "Pete Becker" <petebecker_at_[hidden]>
> At 05:00 PM 8/6/2002 +1000, Andrew J Bromage wrote:
> >Is there any interest in something like this?
> >
> > void call_once(function0<void>& func, once_flag&);
> To paraphrase my recollection of Butenhof's discussion: back in the olden
> days, before POSIX had static initializers for mutexes, once functions
> essential, so that you could guarantee that a mutex had been initialized
> before you used it. That was their primary reason for existing. Once
> initialion of mutexes was added this problem went away, and with it, the
> primary need for once functions.
> Further, a once function won't ever be more efficient than user-written
> code that uses a mutex and a flag, and will often be less efficient. So as
> long as you can statically initialize a mutex, once functions are "merely"
> a convenience.
> Now back to my own opinion, based on the above.
> In C++ we have automatic initialization of static objects, so there is
> less need for once functions.

We have dynamic initialization of static mutex objects, but we do not have
static initialization of mutex objects. Hello initialization order.

> Making them more powerful doesn't seem
> productive, since they will rarely be needed in well-designed code.

The 'powerful' once function and a statically initialized mutex are
equivalent in expressive power; I can do either given the other.

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