Random segfaults in ParticleHP Thermal Scattering Data, which might be due to a race condition

I think I have bumped into a possible race condition, and before investigating much deeper, it would be good to know if someone has bumped into this issue (I am wondering if https://hypernews.slac.stanford.edu/HyperNews/geant4/get/hadronprocess/1692.html posted by @sanchitsharma is related?).

My multi-threaded simulations are randomly segfaulting. It seems that the more threads I have, the likelier it is to crash. The only thing that has changed as far as I can tell is that the name of hydrogen has change from “H” to “TS_H_of_Water” (support for the thermal scattering libraries was already in place, although it had not been used yet).

The segfault happens in here:

#0  std::operator<< <char, std::char_traits<char>, std::allocator<char> > (__os=..., 
__str=<error reading variable: Cannot access memory at address 0x10>)
at /usr/src/debug/gcc-9.2.1-1.fc31.x86_64/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/bits/basic_string.h:2312
#1  0x00007ffff36a0a5c in G4ParticleHPThermalScatteringData::BuildPhysicsTable (this=0xaf7c18, aP=...)
at /home/sergio/src/geant4/source/processes/hadronic/models/particle_hp/src/G4ParticleHPThermalScatteringData.cc:303
303	         G4cout << "Element " << it->first.second->GetName() << ",  internal thermal scattering id " << it->second << G4endl;

The << in #0 seems to be “<< it->first.second->GetName()”.

This was with Geant4 10.5.0, I will test now with 10.5.1.

Has anybody ever bumped into this?

Tested with both 10.5.1 and 10.6.0.beta, same problem.

Never mind. This was due to me trying to handle the G4NeutronHPThermalScatteringData instance instead of simply using “new”. Following the recipe in
http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/ForApplicationDeveloper/html/TrackingAndPhysics/physicsProcess.html#high-precision-neutron-interactions-neutronhp
works fine.