This turned out to be an issue on my side, the problem was I have memory pools which needs to run in serial, hence data was not protected in all places causing random memory corruption. I apologize, thanks for the reply Gavin.


On Mon, Sep 30, 2013 at 8:36 AM, Bo Jensen <jensen.bo@gmail.com> wrote:



On Mon, Sep 30, 2013 at 1:20 AM, Gavin Lambert <gavinl@compacsort.com> wrote:
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?


Worker is an instance of a class that does some work. It can not be become invalid before, since it's destructor is called long after the thread is destroyed. 
 
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.

Thanks, I will change it.
 


   /* 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.)


There's several issues with exceptions, I am following the approach in the last example given in this post :


I have tested it works probably, which it does.
 


_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users