【发布时间】:2016-09-02 18:20:51
【问题描述】:
当我阅读时
错误
The crypt() function returns a pointer to static data, and subsequent calls to crypt() will modify the same data. Likewise, crypt_set_format() modifies static data.
来自:http://www.freebsd.org/cgi/man.cgi?query=crypt&sektion=3
我很害怕每次我打电话给crypt() 时我都必须锁定,但在这个来源
(http://pubs.opengroup.org/onlinepubs/009695399/functions/crypt.html)
我读到了:
crypt() 函数不必是可重入的。不需要可重入的函数不需要是线程安全的。
对我来说什么听起来不合理。
我的意思是如果另一个线程只是将不属于一起的值放入流中,我如何生成可复制的哈希?
是不是这个函数不需要线程安全才能正常工作?
【问题讨论】:
-
不,它不是线程安全的。由于它使用的是相同的内部静态数据结构,因此两个线程同时调用 crypt() 将开始破坏彼此的数据。
标签: c multithreading freebsd crypt