How to ensure the consistency of a multi-threaded simulation in C++?
<p>I have implemented a certain simulation that is multi-threaded for the sake of runtime. However, this causes an inconsistency between my different runs since I'm using an RNG for my simulations. Even thought the RNG is seeded the same way across the threads, and even though GNU's gsl_rng is supposed to be thread-safe(I think it is) it looks like some form of race condition between the threads leads some to generate numbers before other threads do and as such there are small discrepancies between various runs.
I was thinking that one way to fix this would be to pre-compute a fixed number of random numbers and then assign them manually to the threads. However, there would be a huge overhead to store the random numbers (in the order of millions).
I was wondering if there was any better way to deal with this race condition?</p>