
30 Jul
2008
30 Jul
'08
8:20 a.m.
Anthony Williams wrote:
Simon Pickles <sipickles@googlemail.com> 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
Ah the old friend boost::ref. Thanks anthony