From 1c30b6daeff2b98b79596b280958ab6cbef7de43 Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Tue, 17 Sep 2013 03:24:21 +0000 Subject: [PATCH] Fixed the other place where tbb set_ref_count was called before finishing creating children which may throw exceptions, hopefully will fix the intermitant TBB crash when an exception is thrown. --- gtsam/base/treeTraversal-inst.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gtsam/base/treeTraversal-inst.h b/gtsam/base/treeTraversal-inst.h index 6cbb202bf..523fad558 100644 --- a/gtsam/base/treeTraversal-inst.h +++ b/gtsam/base/treeTraversal-inst.h @@ -118,8 +118,7 @@ namespace gtsam { // If we have child tasks, start subtasks and wait for them to complete set_ref_count(1 + (int)node->children.size()); - spawn(childTasks); - wait_for_all(); + spawn_and_wait_for_all(childTasks); } else { @@ -152,15 +151,16 @@ namespace gtsam { tbb::task* execute() { typedef PreOrderTask PreOrderTask; - // Set TBB ref count - set_ref_count(1 + (int)roots.size()); // Create data and tasks for our children tbb::task_list tasks; BOOST_FOREACH(const boost::shared_ptr& root, roots) { + DATA rootData = visitorPre(root, myData); tasks.push_back(*new(allocate_child()) - PreOrderTask(root, visitorPre(root, myData), visitorPre, visitorPost, problemSizeThreshold)); + PreOrderTask(root, rootData, visitorPre, visitorPost, problemSizeThreshold)); } + // Set TBB ref count + set_ref_count(1 + (int)roots.size()); // Spawn tasks spawn_and_wait_for_all(tasks); // Return NULL