[Bug target/94087] std::random_device often fails when used from multiple threads

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Mar 9 09:44:13 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94087

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Carlos O'Ryan from comment #0)
> Creating and using a `std::random_device` object fails when used from
> multiple threads.

That's undefined behaviour. Calling non-const member functions on a single
object from multiple threads is always undefined unless specified otherwise.

It might work "by accident", if GCC detects that your CPU supports the RDRAND
instruction and that can be used (because doing so is stateless) but it will
fail if it has to read from the /dev/random or /dev/urandom devices.


More information about the Gcc-bugs mailing list