[PATCH 2/2] Add single-threaded fast path to rand()
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Thu Mar 21 15:18:31 GMT 2024
Hi,
> i think rand() should be a 2 line function, without any
> locking, since it is *not* required to be thread-safe nor
> crypto quality.
Absolutely.
> but i guess for glibc it's safer to keep the current
> implementation just with single-thread checks.
I think it is useful to rewrite it using a much simpler implementation
that just has 64 bits of global state. Then you don't need any locks at all,
we could use a relaxed atomic operation for updates or add it to TLS
since its small enough.
> either way, it is not the best candidate for rseq
> optimizations, as that complexity is not justified, to
> speed up code with undefined behaviour..
Agreed. The complexity of the current random algorithm and all the
associated locking is already way out of order. Programming is all about
keeping stuff as simple and fast as possible.
Cheers,
Wilco
More information about the Libc-alpha
mailing list