Skip to content

Commit

Permalink
Move function-statics to thread_local in Field
Browse files Browse the repository at this point in the history
  • Loading branch information
makortel committed Jul 3, 2014
1 parent b8841ad commit 9d69846
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions SimG4Core/MagneticField/src/Field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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])<theDelta &&
Expand Down

0 comments on commit 9d69846

Please sign in to comment.