问题描述
限时送ChatGPT账号..寻找线程安全的随机生成器我找到了一个mersenne twister生成器类,作者说如果线程安全:
Looking for a thread safe random generator I found a mersenne twister generator class that the author says if thread safe:
http://www.umiacs.umd.edu/~yangcj/mtrnd.html
但是在研究了代码之后,我看不出它是否是安全线程.那里没有任何类型的锁或任何类似于锁变量的东西.
But after studying the code I cannot see were it is safe thread. There are no locks of any kind or anything resembling a lock variable in there.
这个实现真的是线程安全的吗?如果是这样,魔法是什么?
Is this implementation really thread safe? If so what is the magic?
推荐答案
它似乎是线程安全的,因为可以同时使用两个不同的 MersenneTwist 对象.你不能在两个线程中使用同一个对象而不用锁保护它.
It appears to be thread-safe in the sense that two different MersenneTwist objects can be used concurrently. You can't use the same object in two threads without protecting it with a lock.
我猜作者谈到的原始 C 版本使用了全局或静态变量,所以这是一个改进.
I guess the original C version the author talks about used global or static variables so it's an improvement.
这篇关于线程安全梅森捻线机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论