Boost logo

Boost Users :

From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2008-07-30 04:00:08


Simon Pickles <sipickles_at_[hidden]> writes:

> producer( boost::shared_ptr<std::vector<result> > results,
> boost::mutex& mtx )
> {
> boost::thread( boost::bind( &DoInThread, this, results, mtx )
> ); // actually uses a threadpool but not relevant here.
> }

> I am trying to share a single mutex with both producer and
> consumer. However I get a noncopyable error, even if I pass a
> reference.

boost::bind *copies* its parameters, so you will get an error about
being unable to copy. You need to use boost::ref:

boost::thread( boost::bind( &DoInThread, this, results, boost::ref(mtx) ));

Anthony

-- 
Anthony Williams            | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net