digitalmars.D.bugs - [Issue 5847] New: Threads started by core.thread should have same floating point state as main thread
- d-bugmail puremagic.com (54/54) Apr 16 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5847
- d-bugmail puremagic.com (11/11) Aug 12 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5847
http://d.puremagic.com/issues/show_bug.cgi?id=5847 Summary: Threads started by core.thread should have same floating point state as main thread Product: D Version: unspecified Platform: Other OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: druntime AssignedTo: nobody puremagic.com ReportedBy: dsimcha yahoo.com --- Comment #0 from David Simcha <dsimcha yahoo.com> 2011-04-16 11:28:58 PDT --- The following example code runs the same floating point function in two threads (though not concurrently). The answer produced by each thread is different in the low order bits on Windows: import std.algorithm, core.thread, std.stdio, core.stdc.fenv; real sumRange(const(real)[] range) { writeln("Rounding mode: ", fegetround); // 0 from both threads. return reduce!"a + b"(range); } void main() { immutable n = 1_000_000; immutable delta = 1.0 / n; auto terms = new real[1_000_000]; foreach(i, ref term; terms) { immutable x = ( i - 0.5 ) * delta; term = delta / ( 1.0 + x * x ) * 1; } immutable res1 = sumRange(terms); writefln("%.19f", res1); real res2; auto t = new Thread( { res2 = sumRange(terms); } ); t.start(); t.join(); writefln("%.19f", res2); } Output: Rounding mode: 0 0.7853986633972191094 Rounding mode: 0 0.7853986633972437348 If I change the new Thread statement to the following: auto t = new Thread( { asm { fninit; } res2 = sumRange(terms); } ); then both threads print the same answer. This needs fixing because, when performing floating point operations in parallel, it can lead to results that are non-deterministic and depend on how the work is scheduled. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 16 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5847 David Simcha <dsimcha yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED --- Comment #1 from David Simcha <dsimcha yahoo.com> 2011-08-12 20:30:46 PDT --- This was fixed for 2.053. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 12 2011