From 2e0c0bee376fff63fe782c3c110cda8b58b945ff Mon Sep 17 00:00:00 2001
From: scott snyder <snyder@bnl.gov>
Date: Tue, 16 Nov 2021 01:36:54 +0100
Subject: [PATCH] AthContainers: Missing memory fence.

We were missing a memory fence in Cache::store.
This was causing occasional threading test failures on aarch64.
---
 Control/AthContainers/Root/AuxVectorData.cxx      | 5 ++++-
 Control/AthContainers/test/AuxVectorData_test.cxx | 6 +++---
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/Control/AthContainers/Root/AuxVectorData.cxx b/Control/AthContainers/Root/AuxVectorData.cxx
index 42fa0b11843a..6d0c881998fc 100644
--- a/Control/AthContainers/Root/AuxVectorData.cxx
+++ b/Control/AthContainers/Root/AuxVectorData.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 /**
  * @file AthContainers/src/AuxVectorData.cxx
@@ -515,6 +515,9 @@ void AuxVectorData::Cache::store (SG::auxid_t auxid, void* ptr)
     std::fill (newcache + m_cache_len, newcache + newlen,
                static_cast<void*>(0));
 
+    // The above writes must be visible before we update the cache pointers.
+    AthContainers_detail::fence_seq_cst();
+
     // Store so that other threads can see it.
     // The stores to m_cache must happen before the store to m_cache_len;
     // we use a fence to ensure this.
diff --git a/Control/AthContainers/test/AuxVectorData_test.cxx b/Control/AthContainers/test/AuxVectorData_test.cxx
index fdcd8f60a542..e5f572504af9 100644
--- a/Control/AthContainers/test/AuxVectorData_test.cxx
+++ b/Control/AthContainers/test/AuxVectorData_test.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 // $Id$
@@ -348,8 +348,8 @@ void ThreadingTest::threadedTest()
   AuxVectorData_test b;
   b.setStore (&m_store);
 
-  int nthread = 10;
-  AthContainers_detail::thread threads[10];
+  constexpr int nthread = 10;
+  AthContainers_detail::thread threads[nthread];
   m_sm.lock();
   for (int i=0; i < nthread; i++)
     threads[i] = AthContainers_detail::thread (testThread (*this, b, i));
-- 
GitLab