16
System / Re: multithreading and srand
« on: December 10, 2012, 08:44:55 am »
binary1248, thank you. Thanks to all.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
You didn't show us how you tried to use the mutex, and didn't say how it failed.
tonsThis is the key word.
The alternative is to protect global rand() calls with a mutex. But this can quickly become slow. An own random engine per thread is much cleaner. And you can enforce deterministic generation of random numbers, which may be helpful for debugging.Mutex also fails.
Since the mutex does not work, or I did not use true.
http://www.johndcook.com/cpp_TR1_random.html
I have visual studio 2008. There is no support <random> and rand_r (drand48_r).
Give an example, please.