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

2020-03-09 Thread coryan+gccbugzilla at google dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94087

Carlos O'Ryan  changed:

   What|Removed |Added

 Resolution|INVALID |---
 Status|RESOLVED|UNCONFIRMED

--- Comment #7 from Carlos O'Ryan  ---
(In reply to Jonathan Wakely from comment #6)
> (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.

Each thread is creating its own `std::random_device` so I do not believe this
is applicable.

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

2020-03-08 Thread coryan+gccbugzilla at google dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94087

--- Comment #4 from Carlos O'Ryan  ---
(In reply to Andrew Pinski from comment #1)
> >The bug is *not* present on on Fedora:31 where the compiler reports:
> 
> I doubt it is version based but rather based on what the CPU you are running
> on.


I should have mentioned that I used the same hardware to test with Fedora:31
and openSUSE/Tumbleweed (using Docker in case that matters), so I do not
believe we can attribute the behavior difference to the CPU.

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

2020-03-08 Thread coryan+gccbugzilla at google dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94087

--- Comment #5 from Carlos O'Ryan  ---
(In reply to Andrew Pinski from comment #2)
> (In reply to Andrew Pinski from comment #1)
> > >The bug is *not* present on on Fedora:31 where the compiler reports:
> > 
> > I doubt it is version based but rather based on what the CPU you are running
> > on.
> 
> I Mean what type of CPU you are running on.


Oh, I missed that question, from /proc/cpuinfo (on Linux):

processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 94
model name : Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
stepping : 3
microcode : 0xd6
cpu MHz : 871.966
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36
clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm
constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc
cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est
tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt
tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch
cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi
flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid
rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves
dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear
flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa
itlb_multihit
bogomips : 5424.00
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:

[Bug libstdc++/94087] New: std::random_device often fails when used from multiple threads

2020-03-07 Thread coryan+gccbugzilla at google dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94087

Bug ID: 94087
   Summary: std::random_device often fails when used from multiple
threads
   Product: gcc
   Version: 9.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: coryan+gccbugzilla at google dot com
  Target Milestone: ---

Created attachment 47995
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47995&action=edit
A program to reproduce the problem.

Creating and using a `std::random_device` object fails when used from multiple
threads. A `std::exception` exception is throw with the message "random_device:
rdseed failed", probably from this point in the code:

https://github.com/gcc-mirror/gcc/blob/2a4c59d9aa6b1018fa8f86dd8c0573c1fed3f199/libstdc%2B%2B-v3/src/c%2B%2B11/random.cc#L108

The problem is easy to reproduce, compile the attached program and run it, it
fails every time.  I guess any version where __GLIBCXX__ >= 20200128 would have
this problem.

I just compiled with:

g++ -std=c++17 -pthread -o /tmp/repro-rdseed repro-rdseed.cc

and then run the program using:

/tmp/repro-rdseed

The program exits with 0 on success, 1 on failure, and prints some explanatory
messages (and some version numbers). 


The bug *is* present on openSUSE/Tumbleweed, where the compiler reports:

g++ (SUSE Linux) 9.2.1 20200128 [revision
83f65674e78d97d27537361de1a9d74067ff228d]
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.




The bug is *not* present on on Fedora:31 where the compiler reports:

g++ (GCC) 9.2.1 20190827 (Red Hat 9.2.1-1)
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.





PS: Apologies if I get my version numbers wrong, I am used to using binary
distributions, have not compiled GCC from source in 2 decades or so.