|
Boost : |
From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-08-07 04:47:28
> From: Moore, Dave [mailto:dmoore_at_[hidden]]
> > To truly solve this [and other similar problems], you'd
> need a rather
> > simple mechanism of pre-destructors [base class: call
> join(); in this
> > case] and post-constructors [base class: call "start()"; to
> avoid two
> > phase construction, sort of]. ;-)
>
> Can't your suggestion be solved with something like:
>
> class pre_post_hooks<typename myclass> : public myclass
> {
> public:
> pre_post_hooks() : myclass()
> { start();}
> virtual ~pre_post_hooks()
> { join(); }
> };
>
> modify as necessary for passing args to constructor....
The constructor issue, that is, your need to redirect constructors, means you can't make it an effective template. You have to do it on a case-by-case basis for each class you need to run as a thread. The most a template can do is partially solve the "join()" in the destructor issue. You still couldn't inherit from this "thread wrapper" class to make another thread wrapper, because of the double join() problem, and having to recall start(). You still end up in that all that is left from your thread wrapper is a virtual thread function mechanism, and that is really easy to do using the current Boost.Threads interface anyway.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk