You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After switching to explicit use of tbb::task_arena one of our tests was having a segmentation fault when an exception was thrown. The problem seemed to be coming from an object, whose lifetime was managed by std::shared_ptr<>, being deleted twice. A shared_ptr<> to the object was the return value from the call to tbb::task_arena::execute when the passed in lambda threw an exception. Using valgrind did pinpoint problems with access to the shared_ptr internals after the they had been destroyed. Changing from using the return value from tbb::task_arena::execute to instead passing in the value by reference to the lambda capture made the problem go away.
What follows is a simplified program which also exhibits problems under valgrind.
Thank you for the report. The logic is broken when exception is thrown. The root cause is that we call dtor for the object (shared_ptr) that was not constructed.
template<typename F, typename R>
class task_arena_function : public delegate_base {
F &my_func;
aligned_space<R> my_return_storage;
mutable bool my_constructed{}; // FIX
// The function should be called only once.
bool operator()() const override {
new (my_return_storage.begin()) R(my_func()); // CALL USER FUNCTOR WITH EXCEPTION
my_constructed = true; // FIX
return true;
}
public:
task_arena_function(F& f) : my_func(f) {}
// The function can be called only after operator() and only once.
R consume_result() const {
__TBB_ASSERT(my_constructed, NULL);
return std::move(*(my_return_storage.begin()));
}
~task_arena_function() override {
if (my_constructed) { // FIX
my_return_storage.begin()->~R(); // HERE IS THE PROBLEM
}
}
};
After switching to explicit use of
tbb::task_arena
one of our tests was having a segmentation fault when an exception was thrown. The problem seemed to be coming from an object, whose lifetime was managed bystd::shared_ptr<>
, being deleted twice. Ashared_ptr<>
to the object was the return value from the call totbb::task_arena::execute
when the passed in lambda threw an exception. Usingvalgrind
did pinpoint problems with access to the shared_ptr internals after the they had been destroyed. Changing from using the return value fromtbb::task_arena::execute
to instead passing in the value by reference to the lambda capture made the problem go away.What follows is a simplified program which also exhibits problems under valgrind.
The problem reported by valgrind is
The problem happens using gcc 8.2, 9.0, 10.0 and clang 10.1.
The text was updated successfully, but these errors were encountered: