Boost logo

Boost :

From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-08-07 10:34:17


> -----Original Message-----
> From: William E. Kempf [mailto:williamkempf_at_[hidden]]

> Since call_once relies on static initialization the type has
> to be POD,
> which means it would be more like this:
>
> class once
> {
> public:
> typedef ... flag_type;
> flag_type flag;
> call_once(function0<void>&);
> };
>
> boost::once once = BOOST_ONCE_INIT;
> once.call_once(&foo);
>
> So you change the syntax slightly, but that's about all.
>

Just an idea from following the discussion: Instead of calling the class "once", you could create an interface like this:

boost::static_mutex_init -- equivalent of once_flag_type
boost::static_mutex is a regular class and is implemented like a mutex except it uses call_once mechanisms to make sure the mutex is initialized once in the constructor.

A possibly more extended variation is:
boost::static_mutex_init -- equivalent of once_flag_type
boost::static_mutex_impl is a regular class that inherits from counted_base and is implemented like a mutex except it uses call_once mechanisms to make sure the mutex is initialized once in the constructor. The constructor receives the static_mutex_init by reference.
boost::static_mutex is a wrapper for a shared_ptr to static_mutex_impl, and reimplements all the mutex functions as forwarding calls to static_mutex_impl. Its scoped_locks defined types keep copies of the shared pointer.
boost::static_mutex is copyable and all clients should copy it to make sure it is available after main() returns.

The effect is that you might provide a slightly better interface or one closer to the one you said you'd ideally like to have.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk