Thread-safety of boost RNG

泪湿孤枕 提交于 2019-12-01 06:24:26

Browsing through the Boost mailing list archives gives:

Boost.Random does not maintain global state that would need protection from multi-threading.

Boost.Random is thread-safe as long as you don't access any given object from two threads simultaneously. (Accessing two different objects is ok, as long as they don't share an engine). If you require that kind of safety, it's trivial to roll that on your own with an appropriate mutex wrapper.

If you are worried about thread safety don't use boost, use TRNG. Its a parallel random number generation library built to be run on the TINA cluster in Germany. It allows you to create multiple streams of random numbers. There is a tutorial on how to use TRNG with OpenMP here http://www.lindonslog.com/programming/parallel-random-number-generation-trng/ just like you are trying to do. You create an independent number of streams according to how many threads you are using, and then draw from them by using the rank of the thread. Its all in the above tutorial.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!