由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - rand() in multitreading
相关主题
use abort() to generate coredump (转载)python下的expect
真正的multi-threading是5个thread要5个cpu?那apache是真正的m多线程编程前景如何?
[合集] 为什么多个线程生成的随机数是一样的?c++下如何实现多线程?
Perl多线程的问题[合集] 怎么样提高自己的multi-thread programming能力?
gdb with big core file有谁用TBB吗
node callback的误解why do we need to map user threads to kernel threads?
multi threading 还是 multi processingProblem of Thread by Prof. Lee大伙怎么看?
thread, semaphore, 问题。一个multithread的问题(是不是有人觉的很简单?)
相关话题的讨论汇总
话题: rand话题: running话题: write话题: basically
进入Programming版参与讨论
1 (共1页)
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.

1 (共1页)
进入Programming版参与讨论
相关主题
一个multithread的问题(是不是有人觉的很简单?)gdb with big core file
thread c++ 问题node callback的误解
a question about Nachos in Cmulti threading 还是 multi processing
用多线程怎么比单线程还慢呢?thread, semaphore, 问题。
use abort() to generate coredump (转载)python下的expect
真正的multi-threading是5个thread要5个cpu?那apache是真正的m多线程编程前景如何?
[合集] 为什么多个线程生成的随机数是一样的?c++下如何实现多线程?
Perl多线程的问题[合集] 怎么样提高自己的multi-thread programming能力?
相关话题的讨论汇总
话题: rand话题: running话题: write话题: basically