random is not multithread-safe in Cygwin
Corinna Vinschen
corinna-cygwin@cygwin.com
Mon Nov 13 19:07:44 GMT 2023
On Nov 13 19:04, Bruno Haible via Cygwin wrote:
> Corinna Vinschen wrote:
> > > And indeed glibc, musl libc, AIX, Android, and even NetBSD implement it in a
> > > multithread-safe way.
> >
> > Our code is from FreeBSD, originally. I checked the latest code from
> > FreeBSD. It doesn't lock anything in random() and generates the same
> > error when running the same test app.
> >
> > Why is that ok for FreeBSD?
>
> It is not OK in FreeBSD, either. This is what I noted in the Gnulib manual:
> https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=doc/posix-functions/random.texi
>
> But it is MT-safe in NetBSD (in the '#ifndef SMALL_RANDOM' branch):
> http://cvsweb.netbsd.org/bsdweb.cgi/src/common/lib/libc/stdlib/random.c?rev=1.7&content-type=text/x-cvsweb-markup
Ok, I pushed a patch(*) to make the random(3) functions thread-safe, more
or less following NetBSDs lead. If you get a chance, give the next test
release cygwin-3.5.0-0.459.gd223f095905a a try.
The patch will be part of the next release, 3.4.10.
Thanks,
Corinna
(*) https://sourceware.org/git/?p=newlib-cygwin.git;a=commit;h=06e463223b95
More information about the Cygwin
mailing list