From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2D3C5395CC0D; Thu, 14 May 2020 11:51:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D3C5395CC0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589457119; bh=Rag/S9FiETJAsa5IdlYiB+db+5QBchVQTntUEr1mjzk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=W7DVH5EmZ2iYQrZj91UxN0koYs0S6/W+AUHpqppg1K5QJY+W3eMuCAzw8mXFkZCbk 4BztoqH4ueNe6qp2ztgG9wHijT/m7KdTTBWmKL9KupGuyjuck+fMHE9pV0fSwcKEmA /y/74yVkCHttRRcXfBLapM1VSgKZtNtbGx2Ij//E= From: "rguenther at suse dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/94087] std::random_device often fails when used from multiple threads Date: Thu, 14 May 2020 11:51:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 9.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenther at suse dot de X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 May 2020 11:51:59 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94087 --- Comment #20 from rguenther at suse dot de --- On Thu, 14 May 2020, redi at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94087 >=20 > --- Comment #19 from Jonathan Wakely --- > If you mean the mersenne twister in the std::random_device object, that's= a > union member and doesn't exist when a proper source (/dev/random, rdrand, > rdseed etc) is available. So we'd need to add *another* mersenne twister = object > (which would double the size of std::random_device, changing ABI, or have= to be > global and protected by a mutex, or thread-local) and we'd have to seed i= t so > it's not 100% deterministic, and MT has a state size of 19968 bits which = needs > a lot of seeding. It's not a good choice for many reasons. Doh. OK, guess I'd set up the twister in all cases and make it=20 programatically skip itself when rdrand/rdseed is available so we could easily fall back to it. Not sure what extra state there is that warrants the union, but well ... I suppose simply calling random() from the C library isn't an option ;)=