From 9d69846a52566ac7e71afa5347db83b99f0b9c38 Mon Sep 17 00:00:00 2001 From: Matti Kortelainen Date: Wed, 2 Jul 2014 19:57:59 +0200 Subject: [PATCH] Move function-statics to thread_local in Field --- SimG4Core/MagneticField/src/Field.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/SimG4Core/MagneticField/src/Field.cc b/SimG4Core/MagneticField/src/Field.cc index 90a4123a6238b..4aa7970439226 100644 --- a/SimG4Core/MagneticField/src/Field.cc +++ b/SimG4Core/MagneticField/src/Field.cc @@ -35,8 +35,14 @@ void Field::GetFieldValue(const double xyz[3],double bfield[3]) const throw SimG4Exception( "SimG4CoreMagneticField: Corrupted Event - NaN detected (position)" ) ; } - static float oldx[3] = {1.0e12,1.0e12,1.0e12}; - static double b[3]; + // Which is worse, thread_local static here, or mutable members? + // Mutable members + synchronization would be the most correct. In + // practice I know there is (by construction via + // RunManagerMT/RunManagerMTWorker) one Field object per thread, + // managed via pointers in TLS, so thread_local here is also + // "correct", and fastest to write. + static thread_local float oldx[3] = {1.0e12,1.0e12,1.0e12}; + static thread_local double b[3]; if (theDelta>0. && fabs(oldx[0]-xyz[0])