|
Boost Users : |
Subject: Re: [Boost-users] Valgrind errors with ASIO
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2013-09-30 02:20:06
On 9/30/2013 5:41 PM, Quoth Bo Jensen:
> I am calling it ala like this :
>
> /* Create new tasks */
> basistasks_[workerid] =
> boost::make_shared<boost::packaged_task<BasisSelectRet>
> >(boost::bind(&CallBasisSelection,&worker,boost::ref(io_error_[workerid])));
What is "worker" here? Could it become invalid before the join completes?
Also note that when passing it to a different thread it's safer to allow
the shared_ptr to be copied rather than being passed by reference,
although this probably isn't related to your current problem.
> /* Helper function */
> BasisSelectRet CallBasisSelection(TreeWorker
> *worker,
>
> boost::shared_ptr<ExceptionTransfer> &error)
> {
> BasisSelectRet ret = BasisSelectRetOk;
>
> try
> {
> worker->BasisSelection();
> }
> catch( ... )
> {
> error->SetException(boost::current_exception());
> }
>
> return ret;
> }
You probably shouldn't be catching exceptions here. packaged_task will
do that for you anyway, and as it stands I think there's a slim chance
of a broken_promise exception that will bypass this code, so you'd need
to catch where you're accessing the futures anyway. (If your number of
jobs is larger than your number of threads.)
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