Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-01-16 11:11:32


Elli Barasch wrote:

> Is there a way I can "new" a copy of the shared_ptr onto the stack?
> Something like:
>
> pthread_create(&t,&attr,&func,(void *) new shared_ptr<T>(shp));

The easiest way to do that would be to use Boost.Threads.

void func( shared_ptr<T> p );

boost::thread t( boost::bind( func, shp ) );

If you need to use pthread_create, you might want to look at the source of
Boost.Threads to see how it implements this functionality.

That said, your suggested approach can also work; you'd need to cast the
void* in func back to shared_ptr<T>* ppt and remember to delete it once you
copy *ppt to a local shared_ptr variable.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net