Which Thread is Printing? (Safe MT Messengers)

Screenshot 2024-01-15 at 11.37.58

In my RunAction BeginOfRunAction, I am feeding in a value defined in a user-defined messenger (which is initialized in the constructor). I have it set to print for now to check what value is being read - I am expecting 0.1, but the worker threads are reading 0. However, 0.1 is being printed, though not by the worker threads.

I assumed the 0.1 must therefore be read by the master thread, but when adding if (G4Threading::G4GetThreadId() == G4Threading::IsMasterThread()) condition to the G4cout, it also prints 0. So which thread is reading the correct value that is printing here? How do I ensure my messenger is being read is a way that is thread-safe?

G4UIcommands that also need execution on worker threads need to be marked as such using the G4UICommand::SetToBeBroadcasted(bool) member function. All that should be needed is to call that for the UI command(s) you want to be available to workers, e.g.


Ahh perfect, that’s exactly what I was missing! Thank you for your help :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.