是Windows的rand_s线程安全的? [英] Is Windows' rand_s thread-safe?
本文介绍了是Windows的rand_s线程安全的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正如标题。是令人怀疑的是,但我找不到它的任何地方明确规定。而对于这个属性我不喜欢靠猜测。
Just as in title. Is suspect it is, but I couldn't find it anywhere explicitly stated. And for this property I wouldn't like to rely on speculations.
推荐答案
如果您使用的多线程版本,所有的功能都是线程安全的,因为任何线程特定信息存储在的 TLS 。 rand_s居然不首先使用状态信息,因为它只是调用操作系统API,所以线程安全的问题并不存在于rand_s。兰特(),但是依赖于种子值产生一个随机数。
If you use the multithreaded version of the CRT, all functions are thread safe, because any thread-specific information is stored in TLS. rand_s actually doesn't use state information in the first place, since it just calls an OS API, so question of thread-safety doesn't arise for rand_s. rand(), however depends on a seed value to generate a random number.
这篇关于是Windows的rand_s线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文