ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4TemplateAutoLock< _Mutex_t > Class Template Reference

#include <geant4/tree/geant4-10.6-release/source/global/management/include/G4AutoLock.hh>

+ Inheritance diagram for G4TemplateAutoLock< _Mutex_t >:
+ Collaboration diagram for G4TemplateAutoLock< _Mutex_t >:

Public Types

typedef std::unique_lock
< _Mutex_t > 
unique_lock_t
 
typedef G4TemplateAutoLock
< _Mutex_t > 
this_type
 
typedef unique_lock_t::mutex_type mutex_type
 

Public Member Functions

 G4TemplateAutoLock (mutex_type &_mutex)
 
template<typename Rep , typename Period >
 G4TemplateAutoLock (mutex_type &_mutex, const std::chrono::duration< Rep, Period > &_timeout_duration)
 
template<typename Clock , typename Duration >
 G4TemplateAutoLock (mutex_type &_mutex, const std::chrono::time_point< Clock, Duration > &_timeout_time)
 
 G4TemplateAutoLock (mutex_type &_mutex, std::defer_lock_t _lock) noexcept
 
 G4TemplateAutoLock (mutex_type &_mutex, std::try_to_lock_t)
 
 G4TemplateAutoLock (mutex_type &_mutex, std::adopt_lock_t)
 
 G4TemplateAutoLock (mutex_type *_mutex)
 
 G4TemplateAutoLock (mutex_type *_mutex, std::defer_lock_t _lock) noexcept
 
 G4TemplateAutoLock (mutex_type *_mutex, std::try_to_lock_t)
 
 G4TemplateAutoLock (mutex_type *_mutex, std::adopt_lock_t)
 
void lock ()
 
void unlock ()
 
bool try_lock ()
 
template<typename Rep , typename Period >
bool try_lock_for (const std::chrono::duration< Rep, Period > &)
 
template<typename Clock , typename Duration >
bool try_lock_until (const std::chrono::time_point< Clock, Duration > &)
 
void swap (this_type &other) noexcept
 
bool owns_lock () const noexcept
 

Private Member Functions

template<typename _Tp = _Mutex_t, typename std::enable_if< _is_stand_mutex(_Tp), int >::type = 0>
std::string GetTypeString ()
 
template<typename _Tp = _Mutex_t, typename std::enable_if< _is_recur_mutex(_Tp), int >::type = 0>
std::string GetTypeString ()
 
template<typename _Tp = _Mutex_t, typename std::enable_if< _is_other_mutex(_Tp), int >::type = 0>
std::string GetTypeString ()
 
template<typename _Tp >
void suppress_unused_variable (const _Tp &)
 
void _lock_deferred ()
 
template<typename Rep , typename Period >
void _lock_deferred (const std::chrono::duration< Rep, Period > &_timeout_duration)
 
template<typename Clock , typename Duration >
void _lock_deferred (const std::chrono::time_point< Clock, Duration > &_timeout_time)
 
void PrintLockErrorMessage (std::system_error &e)
 

Detailed Description

template<typename _Mutex_t>
class G4TemplateAutoLock< _Mutex_t >

============================================================================//

void print_threading() { #ifdef G4MULTITHREADED std::cout << "\nUsing G4MULTITHREADED version..." << std::endl; #else std::cout << "\nUsing G4SERIAL version..." << std::endl; #endif }

============================================================================//

typedef std::unique_lock<std::mutex> unique_lock_t; functions for casting G4AutoLock to std::unique_lock to demonstrate that G4AutoLock is NOT polymorphic void as_unique_lock(unique_lock_t* lock) { lock->lock(); } void as_unique_unlock(unique_lock_t* lock) { lock->unlock(); }

============================================================================//

void run(const uint64_t& n) { sync the threads a bit std::this_thread::sleep_for(std::chrono::milliseconds(10));

get two mutexes to avoid deadlock when l32 actually locks G4AutoLock l32(G4TypeMutex<int32_t>(), std::defer_lock); G4AutoLock l64(G4TypeMutex<int64_t>(), std::defer_lock);

when serial: will not execute std::unique_lock::lock() because it overrides the member function l32.lock(); regardless of serial or MT: will execute std::unique_lock::lock() because std::unique_lock::lock() is not virtual as_unique_lock(&l64);

std::cout << "Running iteration " << n << "..." << std::endl; }

============================================================================// execute some work template <typename thread_type="std::thread"> void exec(uint64_t n) { get two mutexes to avoid deadlock when l32 actually locks G4AutoLock l32(G4TypeMutex<int32_t>(), std::defer_lock); G4AutoLock l64(G4TypeMutex<int64_t>(), std::defer_lock);

std::vector<thread_type*> threads(n, nullptr); for(uint64_t i = 0; i < n; ++i) { threads[i] = new thread_type(); (threads[i]) = std::move(thread_type(run, i)); }

when serial: will not execute std::unique_lock::lock() because it overrides the member function l32.lock(); regardless of serial or MT: will execute std::unique_lock::lock() because std::unique_lock::lock() is not virtual as_unique_lock(&l64);

std::cout << "Joining..." << std::endl;

when serial: will not execute std::unique_lock::unlock() because it overrides the member function l32.unlock(); regardless of serial or MT: will execute std::unique_lock::unlock() because std::unique_lock::unlock() is not virtual as_unique_unlock(&l64);

NOTE ABOUT UNLOCKS: in MT, commenting out either l32.unlock(); or as_unique_unlock(&l64); creates a deadlock; in serial, commenting out as_unique_unlock(&l64); creates a deadlock but commenting out l32.unlock(); does not

clean up and join for(uint64_t i = 0; i < n; ++i) { threads[i]->join(); delete threads[i]; } threads.clear(); }

============================================================================//

int main() { print_threading();

uint64_t n = 30; std::cout << "\nRunning with real threads...\n" << std::endl; exec<std::thread>(n); std::cout << "\nRunning with fake threads...\n" << std::endl; exec<G4DummyThread>(n);

}

Definition at line 275 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 275 of file G4AutoLock.hh

Member Typedef Documentation

template<typename _Mutex_t >
typedef unique_lock_t::mutex_type G4TemplateAutoLock< _Mutex_t >::mutex_type

Definition at line 283 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 283 of file G4AutoLock.hh

template<typename _Mutex_t >
typedef G4TemplateAutoLock<_Mutex_t> G4TemplateAutoLock< _Mutex_t >::this_type

Definition at line 282 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 282 of file G4AutoLock.hh

template<typename _Mutex_t >
typedef std::unique_lock<_Mutex_t> G4TemplateAutoLock< _Mutex_t >::unique_lock_t

Definition at line 281 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 281 of file G4AutoLock.hh

Constructor & Destructor Documentation

template<typename _Mutex_t >
G4TemplateAutoLock< _Mutex_t >::G4TemplateAutoLock ( mutex_type _mutex)
inline

Definition at line 294 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 294 of file G4AutoLock.hh

References G4TemplateAutoLock< _Mutex_t >::_lock_deferred().

+ Here is the call graph for this function:

template<typename _Mutex_t >
template<typename Rep , typename Period >
G4TemplateAutoLock< _Mutex_t >::G4TemplateAutoLock ( mutex_type _mutex,
const std::chrono::duration< Rep, Period > &  _timeout_duration 
)
inline

Definition at line 306 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 306 of file G4AutoLock.hh

References G4TemplateAutoLock< _Mutex_t >::_lock_deferred().

+ Here is the call graph for this function:

template<typename _Mutex_t >
template<typename Clock , typename Duration >
G4TemplateAutoLock< _Mutex_t >::G4TemplateAutoLock ( mutex_type _mutex,
const std::chrono::time_point< Clock, Duration > &  _timeout_time 
)
inline

Definition at line 320 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 320 of file G4AutoLock.hh

References G4TemplateAutoLock< _Mutex_t >::_lock_deferred().

+ Here is the call graph for this function:

template<typename _Mutex_t >
G4TemplateAutoLock< _Mutex_t >::G4TemplateAutoLock ( mutex_type _mutex,
std::defer_lock_t  _lock 
)
inlinenoexcept

Definition at line 330 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 330 of file G4AutoLock.hh

template<typename _Mutex_t >
G4TemplateAutoLock< _Mutex_t >::G4TemplateAutoLock ( mutex_type _mutex,
std::try_to_lock_t   
)
inline

Definition at line 351 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 351 of file G4AutoLock.hh

template<typename _Mutex_t >
G4TemplateAutoLock< _Mutex_t >::G4TemplateAutoLock ( mutex_type _mutex,
std::adopt_lock_t   
)
inline

Definition at line 356 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 356 of file G4AutoLock.hh

template<typename _Mutex_t >
G4TemplateAutoLock< _Mutex_t >::G4TemplateAutoLock ( mutex_type _mutex)
inline

Definition at line 366 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 366 of file G4AutoLock.hh

References G4TemplateAutoLock< _Mutex_t >::_lock_deferred().

+ Here is the call graph for this function:

template<typename _Mutex_t >
G4TemplateAutoLock< _Mutex_t >::G4TemplateAutoLock ( mutex_type _mutex,
std::defer_lock_t  _lock 
)
inlinenoexcept

Definition at line 373 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 373 of file G4AutoLock.hh

template<typename _Mutex_t >
G4TemplateAutoLock< _Mutex_t >::G4TemplateAutoLock ( mutex_type _mutex,
std::try_to_lock_t   
)
inline

Definition at line 389 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 389 of file G4AutoLock.hh

template<typename _Mutex_t >
G4TemplateAutoLock< _Mutex_t >::G4TemplateAutoLock ( mutex_type _mutex,
std::adopt_lock_t   
)
inline

Definition at line 393 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 393 of file G4AutoLock.hh

Member Function Documentation

template<typename _Mutex_t >
void G4TemplateAutoLock< _Mutex_t >::_lock_deferred ( )
inlineprivate

Definition at line 482 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 482 of file G4AutoLock.hh

References e, and G4TemplateAutoLock< _Mutex_t >::PrintLockErrorMessage().

Referenced by G4TemplateAutoLock< _Mutex_t >::G4TemplateAutoLock().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename _Mutex_t >
template<typename Rep , typename Period >
void G4TemplateAutoLock< _Mutex_t >::_lock_deferred ( const std::chrono::duration< Rep, Period > &  _timeout_duration)
inlineprivate

Definition at line 496 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 496 of file G4AutoLock.hh

References e, G4TemplateAutoLock< _Mutex_t >::PrintLockErrorMessage(), and G4TemplateAutoLock< _Mutex_t >::suppress_unused_variable().

+ Here is the call graph for this function:

template<typename _Mutex_t >
template<typename Clock , typename Duration >
void G4TemplateAutoLock< _Mutex_t >::_lock_deferred ( const std::chrono::time_point< Clock, Duration > &  _timeout_time)
inlineprivate

Definition at line 513 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 513 of file G4AutoLock.hh

References e, G4TemplateAutoLock< _Mutex_t >::PrintLockErrorMessage(), and G4TemplateAutoLock< _Mutex_t >::suppress_unused_variable().

+ Here is the call graph for this function:

template<typename _Mutex_t >
template<typename _Tp = _Mutex_t, typename std::enable_if< _is_stand_mutex(_Tp), int >::type = 0>
std::string G4TemplateAutoLock< _Mutex_t >::GetTypeString ( )
inlineprivate

Definition at line 443 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 443 of file G4AutoLock.hh

template<typename _Mutex_t >
template<typename _Tp = _Mutex_t, typename std::enable_if< _is_recur_mutex(_Tp), int >::type = 0>
std::string G4TemplateAutoLock< _Mutex_t >::GetTypeString ( )
inlineprivate

Definition at line 447 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 447 of file G4AutoLock.hh

template<typename _Mutex_t >
template<typename _Tp = _Mutex_t, typename std::enable_if< _is_other_mutex(_Tp), int >::type = 0>
std::string G4TemplateAutoLock< _Mutex_t >::GetTypeString ( )
inlineprivate

Definition at line 451 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 451 of file G4AutoLock.hh

template<typename _Mutex_t >
void G4TemplateAutoLock< _Mutex_t >::lock ( )
inline

Definition at line 412 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 412 of file G4AutoLock.hh

Referenced by G4VUPLSplitter< T >::CreateSubInstance(), G4PDefManager::CreateSubInstance(), G4SPSEneDistribution::GenEpnHistEnergies(), G4SPSEneDistribution::GenerateBbodyEnergies(), G4SPSEneDistribution::GenerateCPowEnergies(), mutex::lock(), G4InuclNuclei::makeNuclearFragment(), G4PenelopeRayleighModel::SampleSecondaries(), G4MTRunManagerKernel::StartThread(), and G4Cache< VALTYPE >::~G4Cache().

+ Here is the caller graph for this function:

template<typename _Mutex_t >
bool G4TemplateAutoLock< _Mutex_t >::owns_lock ( ) const
inlinenoexcept

Definition at line 425 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 425 of file G4AutoLock.hh

template<typename _Mutex_t >
void G4TemplateAutoLock< _Mutex_t >::PrintLockErrorMessage ( std::system_error &  e)
inlineprivate

Definition at line 527 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 527 of file G4AutoLock.hh

References G4TemplateAutoLock< _Mutex_t >::suppress_unused_variable().

Referenced by G4TemplateAutoLock< _Mutex_t >::_lock_deferred().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename _Mutex_t >
template<typename _Tp >
void G4TemplateAutoLock< _Mutex_t >::suppress_unused_variable ( const _Tp &  )
inlineprivate

Definition at line 460 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 460 of file G4AutoLock.hh

Referenced by G4TemplateAutoLock< _Mutex_t >::_lock_deferred(), and G4TemplateAutoLock< _Mutex_t >::PrintLockErrorMessage().

+ Here is the caller graph for this function:

template<typename _Mutex_t >
void G4TemplateAutoLock< _Mutex_t >::swap ( this_type other)
inlinenoexcept

Definition at line 424 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 424 of file G4AutoLock.hh

References boost::swap().

+ Here is the call graph for this function:

template<typename _Mutex_t >
bool G4TemplateAutoLock< _Mutex_t >::try_lock ( )
inline

Definition at line 414 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 414 of file G4AutoLock.hh

template<typename _Mutex_t >
template<typename Rep , typename Period >
bool G4TemplateAutoLock< _Mutex_t >::try_lock_for ( const std::chrono::duration< Rep, Period > &  )
inline

Definition at line 417 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 417 of file G4AutoLock.hh

template<typename _Mutex_t >
template<typename Clock , typename Duration >
bool G4TemplateAutoLock< _Mutex_t >::try_lock_until ( const std::chrono::time_point< Clock, Duration > &  )
inline

Definition at line 421 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 421 of file G4AutoLock.hh

template<typename _Mutex_t >
void G4TemplateAutoLock< _Mutex_t >::unlock ( )
inline

Definition at line 413 of file G4AutoLock.hh.

View newest version in sPHENIX GitHub at line 413 of file G4AutoLock.hh

Referenced by G4RootPNtupleManager::AddNtupleRow(), G4VDecayChannel::CheckAndFillDaughters(), G4VDecayChannel::CheckAndFillParent(), G4GeometryWorkspace::CloneParameterisedSolids(), G4GeometryWorkspace::CloneReplicaSolid(), G4Hdf5AnalysisManager::CloseFileImpl(), G4PenelopeGammaConversionModel::ComputeCrossSectionPerAtom(), G4PenelopeRayleighModel::ComputeCrossSectionPerAtom(), G4PenelopePhotoElectricModel::ComputeCrossSectionPerAtom(), G4PenelopeIonisationModel::ComputeDEDXPerVolume(), G4ImportanceConfigurator::Configure(), G4WorkerRunManager::ConstructScoringWorlds(), G4VUPLSplitter< T >::CreateSubInstance(), G4PDefManager::CreateSubInstance(), G4PenelopeIonisationModel::CrossSectionPerVolume(), G4DNAChemistryManager::DeleteInstance(), G4MolecularConfiguration::DeleteManager(), G4ChipsKaonMinusElasticXS::G4ChipsKaonMinusElasticXS(), G4ChipsKaonPlusElasticXS::G4ChipsKaonPlusElasticXS(), G4ChipsKaonPlusInelasticXS::G4ChipsKaonPlusInelasticXS(), G4MTRunManagerKernel::G4MTRunManagerKernel(), G4SPSEneDistribution::GenEpnHistEnergies(), G4SPSEneDistribution::GenerateBbodyEnergies(), G4SPSEneDistribution::GenerateCPowEnergies(), G4SPSAngDistribution::GenerateUserDefPhi(), G4SPSAngDistribution::GenerateUserDefTheta(), G4SPSEneDistribution::GenUserHistEnergies(), G4PenelopeBremsstrahlungModel::GetCrossSectionTableForCouple(), G4LatticeManager::GetLatticeManager(), G4MolecularConfiguration::GetManager(), G4Ellipsoid::GetPointOnSurface(), G4CSGSolid::GetPolyhedron(), G4BooleanSolid::GetPolyhedron(), G4VCSGfaceted::GetPolyhedron(), G4VTwistedFaceted::GetPolyhedron(), G4EllipticalTube::GetPolyhedron(), G4TwistedTubs::GetPolyhedron(), G4Paraboloid::GetPolyhedron(), G4Ellipsoid::GetPolyhedron(), G4Hype::GetPolyhedron(), G4Tet::GetPolyhedron(), G4GenericTrap::GetPolyhedron(), G4MultiUnion::GetPolyhedron(), G4EllipticalCone::GetPolyhedron(), G4TessellatedSolid::GetPolyhedron(), HadrontherapyElectricTabulatedField3D::HadrontherapyElectricTabulatedField3D(), HadrontherapyMagneticField3D::HadrontherapyMagneticField3D(), G4BoldyshevTripletModel::InitialiseForElement(), G4LivermoreRayleighModel::InitialiseForElement(), G4LivermoreGammaConversionModelRC::InitialiseForElement(), G4LivermoreNuclearGammaConversionModel::InitialiseForElement(), G4LivermorePolarizedGammaConversionModel::InitialiseForElement(), G4LivermoreGammaConversionModel::InitialiseForElement(), G4LivermoreComptonModel::InitialiseForElement(), G4LivermorePolarizedRayleighModel::InitialiseForElement(), G4LivermorePolarizedComptonModel::InitialiseForElement(), G4JAEAElasticScatteringModel::InitialiseForElement(), G4LivermorePolarizedPhotoElectricGDModel::InitialiseForElement(), G4LivermoreBremsstrahlungModel::InitialiseForElement(), G4LivermorePolarizedPhotoElectricModel::InitialiseForElement(), G4LowEPComptonModel::InitialiseForElement(), G4LowEPPolarizedComptonModel::InitialiseForElement(), G4RunManagerKernel::InitializePhysics(), G4MolecularConfiguration::G4MolecularConfigurationManager::Insert(), G4DNAChemistryManager::Instance(), G4InuclNuclei::makeNuclearFragment(), G4ITTrackHolder::MasterInstance(), G4AccumulableManager::Merge(), G4RootPNtupleManager::Merge(), G4Hdf5AnalysisManager::OpenFileImpl(), PurgMagTabulatedField3D::PurgMagTabulatedField3D(), G4ITTrackHolder::PushToMaster(), RE05PrimaryGeneratorAction::RE05PrimaryGeneratorAction(), G4LatticeManager::RegisterLattice(), G4PenelopeGammaConversionModel::SampleSecondaries(), G4PenelopeRayleighModel::SampleSecondaries(), G4GeomSplitter< T >::SlaveCopySubInstanceArray(), G4MTRunManagerKernel::StartThread(), TabulatedField3D::TabulatedField3D(), mutex::unlock(), G4XmlAnalysisManager::WriteH1(), G4CsvAnalysisManager::WriteH1(), G4Hdf5AnalysisManager::WriteH1(), G4RootAnalysisManager::WriteH1(), G4XmlAnalysisManager::WriteH2(), G4CsvAnalysisManager::WriteH2(), G4Hdf5AnalysisManager::WriteH2(), G4RootAnalysisManager::WriteH2(), G4XmlAnalysisManager::WriteH3(), G4CsvAnalysisManager::WriteH3(), G4Hdf5AnalysisManager::WriteH3(), G4RootAnalysisManager::WriteH3(), G4XmlAnalysisManager::WriteP1(), G4CsvAnalysisManager::WriteP1(), G4Hdf5AnalysisManager::WriteP1(), G4RootAnalysisManager::WriteP1(), G4XmlAnalysisManager::WriteP2(), G4CsvAnalysisManager::WriteP2(), G4Hdf5AnalysisManager::WriteP2(), and G4RootAnalysisManager::WriteP2().


The documentation for this class was generated from the following file: