ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4atomic.hh File Reference

Definition of the G4atomic class. More...

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

template<typename _Tp >
using G4atomic = _Tp
 

Detailed Description

Definition of the G4atomic class.

Definition in file G4atomic.hh.

Typedef Documentation

template<typename _Tp >
using G4atomic = _Tp

This is an friendly implementation of the STL atomic class. This class has the same interface as the STL atomic but can be used in an extremely similar fashion to plain old data (POD) types. In other words, the copy constructor and assignment operators are defined, and a load() does not need to be called to get the POD value.

IMPORTANT: Care must be taken when using this class as a RHS term. The best use case scenario for this class is as a LHS term that is only used as a RHS term outside of the multithreaded operations on it.

FOR EXAMPLE: Proper use: Goal: sum energy deposited in run Impl: Is a member variable of derived G4VUserActionInitialization (of which there will always be just one instance). Accumulate thread-local energy deposit into EventAction, add to ActionInit at end of event, print sum on master EndOfRunAction Why: the sum is only a LHS term Improper use: Goal: compute error during event processing Impl: sum += x; sum_sq += x*x; counts++; error = sqrt(sum_sq/(sum*sum) - 1/counts; (where sum, sum_sq, counts are G4atomics) Why: This will work but error can/will be wrong when sum, sum_sq, and counts are updated by another thread while error is being calculated, i.e. they are used as RHS terms

Definition at line 264 of file G4atomic.hh.

View newest version in sPHENIX GitHub at line 264 of file G4atomic.hh