Boost logo

Boost :

From: Ulrich Eckhardt (doomster_at_[hidden])
Date: 2008-01-26 04:13:53

On Friday 25 January 2008 19:40, James Sutherland wrote:
> Any thoughts on what could be causing this? I am using boost_1_34_0. I
> don¹t know if this is relevant, but I have a thread adaptor class that
> looks like:
> > class ThreadAdaptor
> > {
> > public:
> > ThreadAdaptor( ExpressionBase& expr ) : expr_(expr) {}
> > ThreadAdaptor(const ThreadAdaptor& ta) : expr_(ta.expr_) {}
> > ~ThreadAdaptor(){}
> > void operator()(){ expr_.evaluate(); }
> > private:
> > ThreadAdaptor& operator=(const ThreadAdaptor&); // no assignment
> > ExpressionBase& expr_;
> > };

If the "ExpressionBase" object is destroyed, that will also render this object
unusable and crash any thread currently working on it, too, so you need to
make sure that doesn't happen. Otherwise, can you provide a minimal
compilable example?

Lastly, your class above is superfluous:

  ExpressionBase x;
  boost::thread th( boost::bind( &ExpressionBase::evaluate, &x));

I.e. you use boost::bind to get a callable from a memberfunction. Note that
passing 'x' into bind will also work but make a copy of it. You can prevent
that using boost::ref() and boost::cref().


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