Question

When I read

BUGS

 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.

from: http://www.freebsd.org/cgi/man.cgi?query=crypt&sektion=3

I was scared about I had to lock each time I'm calling crypt() but on this source (http://pubs.opengroup.org/onlinepubs/009695399/functions/crypt.html)

I read:

The crypt() function need not be reentrant. A function that is not required to be reentrant is not required to be thread-safe.

What sounds not plausible to me.

I mean how can I generate a reproduceable hash, If another thread is just putting values in the flow, which aren't belonging together?

Is it true, that this function doesn't need to be thread safe to work correctly?

Was it helpful?

Solution

It's not thread-safe. The quote you found is simply stating that the implementers weren't required to make the function thread-safe, therefore it isn't. If you call it simultaneously from multiple threads, bad things will happen.

OTHER TIPS

Just responding to this old post to let you know: FreeBSD HEAD (read: 12.0) will provide a copy of crypt_r() that is thread-safe. Enjoy!

FreeBSD man page

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top