Skip to content

Commit

Permalink
Merge pull request kokkos#4144 from masterleinad/host_shared_ptr_clea…
Browse files Browse the repository at this point in the history
…nup_fence

Add memory fence for HostSharedPtr::cleanup()
  • Loading branch information
crtrott authored Jul 7, 2021
2 parents a877c9e + 1381db3 commit 7b5ffcc
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/impl/Kokkos_HostSharedPtr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ class HostSharedPtr {
// object pointed to by m_counter and m_element_ptr.
if (m_control) {
int const count = Kokkos::atomic_fetch_sub(&(m_control->m_counter), 1);
// atomic_fetch_sub might have memory order relaxed so we need to force
// synchronization to avoid multiple threads doing the cleanup.
Kokkos::memory_fence();
if (count == 1) {
(m_control->m_deleter)(m_element_ptr);
m_element_ptr = nullptr;
Expand Down

0 comments on commit 7b5ffcc

Please sign in to comment.