[libc-commits] [libc] [libc][stdlib] Remove LIBC_THREAD_LOCAL from rand_next (PR #96245)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Tue Jun 25 13:09:35 PDT 2024


nickdesaulniers wrote:

> Looking at some other implementations, it seems like ISO C states that the random seed is per-process, but that multiple threads should be _not_ able to interfere with it? I was looking at `glibc` and this seems to be the case https://github.com/bminor/glibc/blob/master/stdlib/random.c#L287.
> 
> So, this to me seems like we'd need to implement some kind of RMW atomic on the underlying state, not just get rid of the thread_local.

FWIW, Bionic uses NetBSD's srandom, which uses a `mutex_t` to guard access to the random seed.
https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/upstream-netbsd/common/lib/libc/stdlib/random.c#304

https://github.com/llvm/llvm-project/pull/96245


More information about the libc-commits mailing list