i*****s 发帖数: 438 | 1 It seems rand() does not work in multi-threading mode.
If the concurrent part contains rand(), then the running
time increases dramatically with each adding thread.
Basically they are running rand() taking turns.
How to deal with this? Write your own random number generator?
Thanks. | X****r 发帖数: 3557 | 2 You could just look at the man page ---
The function rand() is not reentrant or thread-safe, since it uses hid-
den state that is modified on each call. This might just be the seed
value to be used by the next call, or it might be something more elabo-
rate. In order to get reproducible behavior in a threaded application,
this state must be made explicit. The function rand_r() is supplied
with a pointer to an unsigned int, to be used as state. This is a very
small amount of state, so
【在 i*****s 的大作中提到】 : It seems rand() does not work in multi-threading mode. : If the concurrent part contains rand(), then the running : time increases dramatically with each adding thread. : Basically they are running rand() taking turns. : How to deal with this? Write your own random number generator? : Thanks.
|
|