|
Boost : |
From: William E. Kempf (williamkempf_at_[hidden])
Date: 2002-08-07 10:39:30
----- Original Message -----
From: "Yitzhak Sapir" <yitzhaks_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, August 07, 2002 10:34 AM
Subject: RE: [boost] Enhanced call_once()
> > -----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.
This requires, again, for the boost::static_mutex to be a POD type, at which
point the implementation can be made much simpler on most platforms.
> 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.
Copyable semantics for mutex types is questionable at best. If it's
basically a reference copy you only remove some of the dangers of this
operation.
> 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.
Unless I'm missing something in your descriptions, I don't think so.
Bill Kempf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk