[cpp-threads] Update on N2889/N2880/N2901

Boehm, Hans hans.boehm at hp.com
Tue Jun 23 01:35:26 BST 2009


Thanks.  I was clearly missing something.

Getting back to the original issue, shared_ptr does seem to already expose the basic problems with destruction of thread_locals.  Destroying a thread_local shared_ptr late is clearly not always safe.  But on second thought that's clearly true for other reasons anyway, since the shared_ptr destructor is likely to invoke other arbitrary destructors.  Somehow giving shared_ptr exceptional status seems pretty hopeless.

Hans

> -----Original Message-----
> From: cpp-threads-bounces at decadentplace.org.uk 
> [mailto:cpp-threads-bounces at decadentplace.org.uk] On Behalf 
> Of Howard Hinnant
> Sent: Monday, June 22, 2009 4:26 PM
> To: C++ threads standardisation
> Subject: Re: [cpp-threads] Update on N2889/N2880/N2901
> 
> On Jun 22, 2009, at 6:47 PM, Boehm, Hans wrote:
> 
> > Shared_ptr has a constructor
> >
> > template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
> >
> > However, since the allocator type A is not part of the shared_ptr 
> > type, how does this work?  Assuming I construct one with a non- 
> > default allocator type but, say, no interesting allocator 
> state a, how 
> > does shared_ptr know how to deallocate the reference count on 
> > destruction of the final pointer to an object?
> >
> > This seems strange.  I'm either missing something, or we 
> have another 
> > bug in the draft here.
> 
> It stores the (possibly stateful) allocator right next to the 
> (possibly stateful) deleter, and the Y* (not T*).  This is 
> done by having a:
> 
> class control_block_base
> {
> public:
>      virtual void delete_it() = 0;
> };
> 
> template <class Y, class D, class A>
> class control_block
>     : public control_block_base
> {
>      Y y_;
>      D d_;
>      A a_;
>     ...
>      virtual void delete_it();  // delete y_ using d_ and 
> deallocate using a_ };
> 
> 
> template <class T>
> class shared_ptr
> {
>      control_block_base* ptr_;
>      ...
>      template <class Y, class D, class A>
>      shared_ptr(Y y, D d, A a)
>         : ptr_(new control_block<Y, D, A>(y, d, a)) {}
> 
>      ~ shared_ptr() {ptr_->delete_it();} };
> 
> (or something along those lines; I've ignored some important details).
> 
> -Howard
> 
> 
> --
> 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