线程安全梅森捻线机 [英] Thread safe mersenne twister

查看:26
本文介绍了线程安全梅森捻线机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找线程安全的随机生成器我找到了一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆