In your st, sruct Data, make the ptr a shared_ptr with custom deleter which does nothing.
Mateusz Loskot
(Sent from mobile, apology for top-posting and broken quotes)
I have an application where I need to pass "this" in a callback belonging to a class to a function using a shared_ptr in another thread
In code:
struct Data
{
Data( void* p ) :
ptr( p )
{
}
boost::shared_ptr<void> ptr;
};
void threadA( Data* d )
{
boost::shared_ptr<void> ptr( d->ptr );
delete d;
// use ptr
}
class A
{
void init_thread()
{
Data* data = new Data( this );
boost.thread t( boost::bind( threadA, data ) );
}
};
The problem is obvious. Once threadA closes, the shared ptr is destroyed as its count is 0 and as it points to the this of class A this gets deleted too.
However my class A is still active and should not get deleted. How can I work around this?
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users