Skip to content

Commit

Permalink
[oneDPL][tbb] + memory leaks fix (sort/stable sort, tbb backend) (#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDvorskiy authored Jun 1, 2024
1 parent 8085f5f commit 481272b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions include/oneapi/dpl/pstl/parallel_backend_tbb.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ class __root_task
friend class __func_task<_Func>;
};

#else // TBB_INTERFACE_VERSION <= 12000
#else // TBB_INTERFACE_VERSION > 12000
class __task : public tbb::detail::d1::task
{
protected:
Expand Down Expand Up @@ -644,10 +644,16 @@ class __func_task : public __task

assert(__parent != nullptr);
assert(__parent->_M_refcount.load(::std::memory_order_relaxed) > 0);
if (--__parent->_M_refcount == 0)

auto __refcount = --__parent->_M_refcount;

// Placing the deallocation after the refcount decrement allows another thread to proceed with tree
// folding concurrently with this task cleanup.
__alloc.deallocate(this, *__ed);

if (__refcount == 0)
{
assert(__next == nullptr);
__alloc.deallocate(this, *__ed);
return __parent;
}

Expand Down

0 comments on commit 481272b

Please sign in to comment.