Boost logo

Boost :

From: Sean Kelly (sean_at_[hidden])
Date: 2004-02-14 01:26:27

On Fri, 13 Feb 2004, Andreas Huber wrote:
> Sean Kelly wrote:
> Did you have something like this in mind:

No. I was thinking about a class that didn't use the existing
boost::thread class at all. Downside is redundant code, but not very

class thread_base
        virtual ~thread();
        void start();
        void join() const;

        virtual void operator()() = 0;

        static unsigned __stdcall thread_func( void* arg );
        void* m_thread;
        unsigned m_id;
#elif defined( BOOST_HAS_PTHREADS )
        static void* thread_func( void* arg );
        pthread_t m_thread;

> And call start() in the subclass constructor and call join() in the subclass
> destructor, what can be easily forgotten by someone deriving from
> thread_base. I think this was one of the reasons why the design of
> boost::thread did not go down this road...

The user could delete the object passed to boost::thread with the existing
design and there would be no provision for calling join. If this is
enough of a concern, make the thread_base destructor a pure virtual
function and document the need to call join.


Boost list run by bdawes at, gregod at, cpdaniel at, john at