线程安全梅森捻线机

编程入门 行业动态 更新时间:2024-10-28 08:24:44
本文介绍了线程安全梅森捻线机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-30 16:26:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1396348.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   梅森   捻线机

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!