Boost logo

Boost :

From: jmzorko_at_[hidden]
Date: 2006-08-22 18:04:25


Hello, all ...

OK, i'm experiencing a crash every now and then (WIndows) and all-the-
freakin'-time (Mac OSX) for my app. Looking into it, I see this,
which I wrote before I understood the beauty of scoped_ptr:

template< class T > class Thread
{
public:
        Thread() : pBoostThread( NULL ), pThreadFunction( NULL ),
m_ExitSignal( false ) {}

        return_status Init( return_status ( *pFunc )( Thread * ), T varArg )
        {
                pThreadFunction = pFunc;
                varThreadArg = varArg;
                return SUCCESS;
        }

        return_status Start()
        {
                pBoostThread = new boost::thread( boost::bind( pThreadFunction,
this ) );
                return SUCCESS;
        }

        .
        .
        .

        return_status Exit( unsigned long exit_code )
        {
                .
                .
                .
                
                if ( pBoostThread ) delete pBoostThread; // ouch!!!

                .
                .
                .
        }
};

I tried wrapping the icky "new boost::thread< ... >" in a
boost::scoped_ptr, like so:

                pBoostThread = new boost::scoped_ptr< boost::thread( boost::bind
( pThreadFunction, this ) ) >;

... but the compiler didn't like it (boost::bind cannot appear inside
a constant expression). What is the proper way of wrapping a
boost::thread in a scoped_ptr? My boost::thread has to be on the
heap, because the function pointer assigned to it is defined _after_
the Thread class is instantiated.

Any help would be appreciated greatly :-)

Regards,

John

Falling You - exploring the beauty of voice and sound
http://www.fallingyou.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk