
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 much: class thread_base { public: thread_base(); virtual ~thread(); void start(); void join() const; private: virtual void operator()() = 0; #if defined( BOOST_HAS_WINTHREADS ) 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; #endif };
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. Sean