Boost logo

Boost :

From: williamkempf_at_[hidden]
Date: 2001-07-02 13:33:51


--- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> From: <williamkempf_at_h...>
> > --- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
>
> > > class thread_group
> > > {
> > > public:
> > >
> > > // all implicit members are fine and useful
> > >
> > > template<class F> void create(F f)
> > > {
> > > v_.push_back(thread::create(f));
> > > }
> > >
> > > void join_all()
> > > {
> > > thread::join(v_.begin(), v_.end());
> > > }
> > >
> > > private:
> > >
> > > std::vector<thread::ref> v_;
> > > };
> > >
> > > As you can see, it's very similar to my vector example.
> >
> > There are two problems here. First, as I pointed out the details
are
> > hidden in the other concept, so the ease of use is not impacted.
>
> Ease of use - provided you have a working thread_group - if of
course not
> impacted. Implementing a thread_group does, however, demonstrate
the ease of
> use of the base design.

No, it really doesn't. Remember, the original pattern didn't use a
thread group, it used an array of std::auto_ptrs, and it's ease of
use was nearly identical. Further, the implementation of the thread
group I give below (once my mistake was corrected) shows the
implementation was not adversely impacted either (at least not to an
extent to warrant a thread ref design).

> > Second, you chose to use a ref-count design internally, when such
a
> > design is not needed.
> >
> > class thread_group
> > {
> > public:
> > // all implicit members are fine and useful
> >
> > template<class F> void create(F f)
> > {
> > v_.push_back(new thread(f));
> > }
> >
> > void join_all()
> > {
> > std::vector<thread*>::iterator it = v_.begin();
> > while (it != v_.end())
> > {
> > (*it)->join();
> > it = v_.erase(it);
> > }
> > }
> >
> > private:
> > std::vector<thread*> v_;
> > };
> >
> > You should note that like you I didn't include proper
> > synchronization, so this implementation isn't valid, but it
> > illustrates the point.
>
> You didn't say anything about sharing a thread_group between
threads, so a
> non-synchronized thread_group still matches the ad-hoc
specification given
> in your 'void foo()' example.

True... what I had in mind and what was obvious from the posts are
two different things.
 
> > My implementation required no reference
> > management, only explicit lifetime management.
>
> And explicit management is error prone, as you have demonstrated.

Explicit management isn't error prone. Manual management is. The
std::auto_ptr<> uses explicit management, and errors don't occur
because of this.

Bill Kempf


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