random is not multithread-safe in Cygwin
Bruno Haible
bruno@clisp.org
Fri Nov 10 16:19:47 GMT 2023
The function 'random' is, unlike 'rand', not marked as not MT-safe in POSIX
[1][2]. Thus it must be multithread-safe [3]:
"Each function defined in the System Interfaces volume of POSIX.1-2017
is thread-safe unless explicitly stated otherwise."
And indeed glibc, musl libc, AIX, Android, and even NetBSD implement it in a
multithread-safe way.
On Cygwin 2.9.0 and 3.4.6, it is not multithread-safe.
How to reproduce:
1. Compile the attached program.
$ x86_64-pc-cygwin-gcc foo.c
2. Run it.
$ ./a.exe
Expected: No output.
Actual: Output such as
Expected value #367 not found in multithreaded results.
[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/initstate.html
[2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/rand.html
[3] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_407
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.c
Type: text/x-csrc
Size: 4391 bytes
Desc: not available
URL: <https://cygwin.com/pipermail/cygwin/attachments/20231110/e93efd63/attachment.bin>
More information about the Cygwin
mailing list