Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
|
#include <G4AutoLock.hh>
Public Types | |
using | unique_lock_t = std::unique_lock< _Mutex_t > |
using | this_type = G4TemplateAutoLock< _Mutex_t > |
using | mutex_type = typename unique_lock_t::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 |
============================================================================//
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 273 of file G4AutoLock.hh.
using G4TemplateAutoLock< _Mutex_t >::mutex_type = typename unique_lock_t::mutex_type |
Definition at line 281 of file G4AutoLock.hh.
using G4TemplateAutoLock< _Mutex_t >::this_type = G4TemplateAutoLock<_Mutex_t> |
Definition at line 280 of file G4AutoLock.hh.
using G4TemplateAutoLock< _Mutex_t >::unique_lock_t = std::unique_lock<_Mutex_t> |
Definition at line 279 of file G4AutoLock.hh.
|
inline |
Definition at line 292 of file G4AutoLock.hh.
|
inline |
Definition at line 304 of file G4AutoLock.hh.
|
inline |
Definition at line 318 of file G4AutoLock.hh.
|
inlinenoexcept |
Definition at line 328 of file G4AutoLock.hh.
|
inline |
Definition at line 349 of file G4AutoLock.hh.
|
inline |
Definition at line 354 of file G4AutoLock.hh.
|
inline |
Definition at line 364 of file G4AutoLock.hh.
|
inlinenoexcept |
Definition at line 371 of file G4AutoLock.hh.
|
inline |
Definition at line 387 of file G4AutoLock.hh.
|
inline |
Definition at line 391 of file G4AutoLock.hh.
|
inline |
Definition at line 410 of file G4AutoLock.hh.
Referenced by G4PDefManager::CreateSubInstance(), G4VUPLSplitter< T >::CreateSubInstance(), mutex::lock(), G4InuclNuclei::makeNuclearFragment(), G4PenelopeRayleighModel::SampleSecondaries(), G4PenelopeRayleighModelMI::SampleSecondaries(), G4MTRunManagerKernel::StartThread(), and G4Cache< VALTYPE >::~G4Cache().
|
inlinenoexcept |
Definition at line 427 of file G4AutoLock.hh.
|
inlinenoexcept |
Definition at line 426 of file G4AutoLock.hh.
|
inline |
Definition at line 412 of file G4AutoLock.hh.
|
inline |
Definition at line 415 of file G4AutoLock.hh.
|
inline |
Definition at line 421 of file G4AutoLock.hh.
|
inline |
Definition at line 411 of file G4AutoLock.hh.
Referenced by G4NuclearLevelData::AddPrivateData(), G4ConvergenceTester::AddScore(), G4NeutronCaptureXS::BuildPhysicsTable(), G4NeutronElasticXS::BuildPhysicsTable(), G4NeutronInelasticXS::BuildPhysicsTable(), G4ParticleInelasticXS::BuildPhysicsTable(), G4VDecayChannel::CheckAndFillDaughters(), G4VDecayChannel::CheckAndFillParent(), G4DNAMolecularMaterial::Clear(), G4GeometryWorkspace::CloneReplicaSolid(), G4Hdf5AnalysisManager::CloseFileImpl(), G4Hdf5FileManager::CloseFileImpl(), G4PenelopeGammaConversionModel::ComputeCrossSectionPerAtom(), G4PenelopePhotoElectricModel::ComputeCrossSectionPerAtom(), G4PenelopeRayleighModel::ComputeCrossSectionPerAtom(), G4PenelopeRayleighModelMI::ComputeCrossSectionPerAtom(), G4PenelopeIonisationModel::ComputeDEDXPerVolume(), G4ImportanceConfigurator::Configure(), G4WorkerRunManager::ConstructScoringWorlds(), G4PDefManager::CreateSubInstance(), G4VUPLSplitter< T >::CreateSubInstance(), G4PenelopeIonisationModel::CrossSectionPerVolume(), G4DNAChemistryManager::DeleteInstance(), G4MolecularConfiguration::DeleteManager(), G4GeometryWorkspace::DestroyWorkspace(), G4ChipsKaonMinusElasticXS::G4ChipsKaonMinusElasticXS(), G4ChipsKaonPlusElasticXS::G4ChipsKaonPlusElasticXS(), G4ChipsKaonPlusInelasticXS::G4ChipsKaonPlusInelasticXS(), G4MTRunManagerKernel::G4MTRunManagerKernel(), G4VAnalysisManager::G4VAnalysisManager(), G4VRangeToEnergyConverter::G4VRangeToEnergyConverter(), G4NistManager::GetICRU90StoppingData(), G4NuclearLevelData::GetInstance(), G4LatticeManager::GetLatticeManager(), G4NuclearLevelData::GetLevelManager(), G4MolecularConfiguration::GetManager(), G4CutTubs::GetPointOnSurface(), G4Ellipsoid::GetPointOnSurface(), G4GenericPolycone::GetPointOnSurface(), G4Polycone::GetPointOnSurface(), G4Polyhedra::GetPointOnSurface(), G4BooleanSolid::GetPolyhedron(), G4MultiUnion::GetPolyhedron(), G4CSGSolid::GetPolyhedron(), G4Ellipsoid::GetPolyhedron(), G4EllipticalCone::GetPolyhedron(), G4EllipticalTube::GetPolyhedron(), G4GenericTrap::GetPolyhedron(), G4Hype::GetPolyhedron(), G4Paraboloid::GetPolyhedron(), G4TessellatedSolid::GetPolyhedron(), G4Tet::GetPolyhedron(), G4TwistedTubs::GetPolyhedron(), G4VCSGfaceted::GetPolyhedron(), G4VTwistedFaceted::GetPolyhedron(), G4AtomicTransitionManager::Initialise(), G4UrbanMscModel::Initialise(), G4WentzelOKandVIxSection::InitialiseA(), G4BoldyshevTripletModel::InitialiseForElement(), G4JAEAElasticScatteringModel::InitialiseForElement(), G4JAEAPolarizedElasticScatteringModel::InitialiseForElement(), G4LivermoreBremsstrahlungModel::InitialiseForElement(), G4LivermoreComptonModel::InitialiseForElement(), G4LivermoreGammaConversion5DModel::InitialiseForElement(), G4LivermoreGammaConversionModel::InitialiseForElement(), G4LivermoreNuclearGammaConversionModel::InitialiseForElement(), G4LivermorePolarizedComptonModel::InitialiseForElement(), G4LivermorePolarizedGammaConversionModel::InitialiseForElement(), G4LivermorePolarizedRayleighModel::InitialiseForElement(), G4LivermoreRayleighModel::InitialiseForElement(), G4LowEPComptonModel::InitialiseForElement(), G4LowEPPolarizedComptonModel::InitialiseForElement(), G4DNAMolecularMaterial::Initialize(), G4RunManagerKernel::InitializePhysics(), G4MolecularConfiguration::G4MolecularConfigurationManager::Insert(), G4DNAChemistryManager::Instance(), G4EmParameters::Instance(), G4FTFTunings::Instance(), G4HadronicParameters::Instance(), G4InuclNuclei::makeNuclearFragment(), G4ITTrackHolder::MasterInstance(), G4AccumulableManager::Merge(), G4Hdf5AnalysisManager::OpenFileImpl(), G4ITTrackHolder::PushToMaster(), G4LatticeManager::RegisterLattice(), G4PenelopeGammaConversionModel::SampleSecondaries(), G4PenelopeRayleighModel::SampleSecondaries(), G4PenelopeRayleighModelMI::SampleSecondaries(), G4IonisParamMat::SetDensityEffectParameters(), G4ScoringProbe::SetupGeometry(), G4GeomSplitter< T >::SlaveCopySubInstanceArray(), G4MTRunManagerKernel::StartThread(), mutex::unlock(), G4LogicalVolumeStore::UpdateMap(), G4PhysicalVolumeStore::UpdateMap(), G4RegionStore::UpdateMap(), G4SolidStore::UpdateMap(), and G4NuclearLevelData::UploadNuclearLevelData().