Boost logo

Boost Users :

From: peter_foelsche_at_[hidden]
Date: 2008-07-30 20:46:18


what is the problem here which prevents you from using a pointer?
I tend to avoid writeable references, since they obfuscate code.

Peter

-----Original Message-----
From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Simon Pickles
Sent: Wednesday, July 30, 2008 01:21
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] Passing Mutexes

Anthony Williams wrote:
> 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
>
Ah the old friend boost::ref. Thanks anthony
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


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