|
Boost : |
From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-08-06 10:57:50
> -----Original Message-----
> From: Peter Dimov [mailto:pdimov_at_[hidden]]
> Sent: Tuesday, August 06, 2002 4:37 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] Re: Re: Threads & Exceptions
>
> Apart from that:
>
> void join_and_delete(boost::thread * pt)
> {
> pt->join();
> delete pt;
> }
>
> class oo_thread: noncopyable
> {
> private:
>
> shared_ptr<boost::thread> pt;
>
> public:
>
> void start()
> {
> pt.reset(new boost::thread(bind(&oo_thread::run, this)),
> join_and_delete);
> }
>
> private:
>
> virtual void run() = 0;
> };
>
One of the things I like about the Boost.Threads model which does not have a virtual run() function is that it makes you think about bugs like what I think is a bug in the above code, where run(), a virtual function could continue running and accessing the descendant of oo_thread after the destructor of the oo_thread's descendant has been called, but before pt has been destructed.
I do use "thread wrapper classes", but with a scoped_ptr, and I do it on a class by class basis, where operator() (my equivalent of run) is never virtual if it's in the same class as the owner of the scoped_ptr.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk