diff --git a/Calorimeter/CaloG4Sim/CaloG4Sim/ATLAS_CHECK_THREAD_SAFETY b/Calorimeter/CaloG4Sim/CaloG4Sim/ATLAS_CHECK_THREAD_SAFETY new file mode 100644 index 0000000000000000000000000000000000000000..bd029a61c8f975e53c6ba99cdaea0e49646e0942 --- /dev/null +++ b/Calorimeter/CaloG4Sim/CaloG4Sim/ATLAS_CHECK_THREAD_SAFETY @@ -0,0 +1 @@ +Calorimeter/CaloG4Sim diff --git a/Calorimeter/CaloG4Sim/CaloG4Sim/EscapedEnergyRegistry.h b/Calorimeter/CaloG4Sim/CaloG4Sim/EscapedEnergyRegistry.h index d25bb6f0d59f34e87daa3eab40c94f672a1ab47f..8d82088b898c997dfa990b86d5a6e68de86e326f 100644 --- a/Calorimeter/CaloG4Sim/CaloG4Sim/EscapedEnergyRegistry.h +++ b/Calorimeter/CaloG4Sim/CaloG4Sim/EscapedEnergyRegistry.h @@ -1,11 +1,12 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef CaloG4_EscapedEnergyRegistry_H #define CaloG4_EscapedEnergyRegistry_H #include "CaloG4Sim/VEscapedEnergyProcessing.h" +#include "CxxUtils/checker_macros.h" #include "globals.hh" #include <map> @@ -75,7 +76,7 @@ namespace CaloG4 // Thread-to-EscapeEnergyRegistry concurrent map type using EERThreadMap_t = tbb::concurrent_unordered_map< std::thread::id, EscapedEnergyRegistry*, std::hash<std::thread::id> >; // Concurrent map of EERs, one for each thread - static EERThreadMap_t m_EERThreadMap; + static EERThreadMap_t m_EERThreadMap ATLAS_THREAD_SAFE; // @brief Search inside m_EERThreadMap the element with the current threadID // and return it or return a null pointer if the element is not found static EscapedEnergyRegistry* getEER(); diff --git a/Calorimeter/CaloG4Sim/src/CalibrationDefaultProcessing.cc b/Calorimeter/CaloG4Sim/src/CalibrationDefaultProcessing.cc index c0fd10089dfb6e5fc0b5c96c74626f4fe97caa34..a03b0a2db37c0a9c0a95ace44adfb4704bc79881 100644 --- a/Calorimeter/CaloG4Sim/src/CalibrationDefaultProcessing.cc +++ b/Calorimeter/CaloG4Sim/src/CalibrationDefaultProcessing.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CalibrationDefaultProcessing @@ -20,6 +20,7 @@ #include "CaloG4Sim/CalibrationDefaultProcessing.h" #include "CaloG4Sim/SimulationEnergies.h" +#include "CxxUtils/checker_macros.h" // For the event-level flag #include "MCTruth/AtlasG4EventUserInfo.h" @@ -32,6 +33,7 @@ #include "GaudiKernel/Bootstrap.h" #include "GaudiKernel/ISvcLocator.h" +#include <atomic> namespace G4UA { @@ -79,7 +81,9 @@ namespace G4UA // this step. Note that we have to "cast away" const-ness for // the G4Step*, due to how G4VSensitiveDetector::Hit() is // defined. - m_defaultSD->Hit( const_cast<G4Step*>(a_step) ); + // Should be ok, since Geant doesn't do intra-event parallelism. + G4Step* step_nc ATLAS_THREAD_SAFE = const_cast<G4Step*> (a_step); + m_defaultSD->Hit( step_nc ); // Update the step info atlasG4EvtUserInfo->SetLastProcessedBarcode( track->GetTrackID() ); @@ -88,10 +92,8 @@ namespace G4UA } else { - // FIXME - thread unsafe static!!! - static G4bool warningPrinted = false; - if ( ! warningPrinted ) { - warningPrinted = true; + static std::atomic_flag warningPrinted ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT; + if ( ! warningPrinted.test_and_set() ) { G4cout << "CaloG4::CalibrationDefaultProcessing::SteppingAction - " << G4endl << " A default calibration sensitive detector was not defined."