[cpp-threads] RE: volatile, memory models, threads

Boehm, Hans hans.boehm at hp.com
Sat Mar 4 02:09:01 GMT 2006


Maybe.  You probably need another variant where the test is on a NULL
pointer.  And I would probably find the explicit DCL version at least as
easy to read.  And you're making some strong compiler assumptions, I
suspect.

Hans

> -----Original Message-----
> From: cpp-threads-bounces at decadentplace.org.uk 
> [mailto:cpp-threads-bounces at decadentplace.org.uk] On Behalf 
> Of Peter Dimov
> Sent: Friday, March 03, 2006 5:45 PM
> To: C++ threads standardisation
> Subject: Re: [cpp-threads] RE: volatile, memory models, threads
> 
> Boehm, Hans wrote:
> 
> > If you are filling in a data member of a dynamically 
> allocated class 
> > on demand, e.g. because it only needs to be computed for a small 
> > subset of the instances, but needs to be repeatedly accessed for 
> > those.
> 
> class X
> {
> private:
> 
>     T * pt_;
>     once_flag ptf_;
> 
>     void init_pt( /* args */ )
>     {
>         pt_ = new T( /*args */ );
>     }
> 
> public:
> 
>     void f()
>     {
>         // needs *pt_
> 
>         call_once( ptf_, &X::init_pt, this /*, args */ );
> 
>         // or ptf_.call( ... )
> 
>         // use *pt_
>     }
> };
> 
> It's slightly more awkward with pthread_once since it can't 
> pass arguments ot invoke member functions, but "our" 
> call_once need not be so limited.
> 
> A language/library that doesn't provide a better alternative 
> to DCL is... 
> not something to be proud of.
> 
> 
> --
> cpp-threads mailing list
> cpp-threads at decadentplace.org.uk
> http://www.decadentplace.org.uk/cgi-bin/mailman/listinfo/cpp-threads
> 



More information about the cpp-threads mailing list