Message: Re: How to get thread id? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Idea Re: How to get thread id?  

Forum: Multithreading
Re: Question How to get thread id? (Jungwook Shin)
Date: 24 Jul, 2013
From: Andrea Dotti <Andrea Dotti>

Hello, in version 10.0.beta G4GetThreadId() is not fully implemented. You need to use the G4GetPidId() that returns the unique PID of the thread. In final public release G4GetThreadId() will return an integer representing the thread number and will be reproducible between runs (i.e. provided the number of threads does not change between execution of the same application a call of G4GetThreadId() from thread simulating event number XYZ will always return the same id).

A possible workaround is something similar to the following snippet of code that, however, does not guarantee reproducibility between runs:

#include "G4AutoLock.hh"

namespace {
   G4Mutex myMutex = G4MUTEX_INITIALIZER;
   static G4int ctr = 0;
}

G4int myId() {
   G4AutoLock l(&myMutex);
   return ctr++;
}

Regards, Andrea

 Add Message Add Message
to: "Re: How to get thread id? "

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews