jmeubank / tdm-gcc

TDM-GCC is a cleverly disguised GCC compiler for Windows!
https://jmeubank.github.io/tdm-gcc/
572 stars 49 forks source link

Calculations in threads are having different results with double types #27

Closed Zaita closed 3 years ago

Zaita commented 3 years ago

I have provided Pastebin for my code: https://pastebin.com/thTapSgn

The issue that I am having is that I am getting different results based on whether or not my calculation is happening within a thread or not. This appears to only happen with TDM-GCC 9.2.0 and not G++/GCC. Not sure if this is an issue in the upstream MinGW/MinGW64 projects.

Compiling this with TDM-GCC 9.2.0 D:\Workspaces\Testing\ThreadDoublePrecision\src>g++ --version g++ (tdm64-1) 9.2.0

Using the following compiler options:

g++ -std=c++17 -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\ThreadDoublePrecision.o" "..\\src\\ThreadDoublePrecision.cpp" 
g++ -o ThreadDoublePrecision.exe "src\\ThreadDoublePrecision.o" -lpthread

Produces this output:

Local  = 0.0010370292068795884059
Local  = 0.0010370292068795884059
Thread = 0.0010370292068795879722
Thread = 0.0010370292068795879722

When I run this on GodBolt.org, WSL2 and Linux natively with GCC/G++ I get this output:

zaita@Anubis:~$ ./a.out
Local  = 0.0010370292068795884059
Local  = 0.0010370292068795884059
Thread = 0.0010370292068795884059
Thread = 0.0010370292068795884059
Zaita commented 3 years ago

msys latest:

Zaita@Anubis MSYS ~
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-msys/10.2.0/lto-wrapper.exe
Target: x86_64-pc-msys
Configured with: /c/_/S/gcc/src/gcc-10.2.0/configure --build=x86_64-pc-msys --prefix=/usr --libexecdir=/usr/lib --enable-bootstrap --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --with-arch=x86-64 --with-tune=generic --disable-multilib --enable-__cxa_atexit --with-dwarf2 --enable-languages=c,c++,fortran,lto --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --disable-libssp --disable-win32-registry --disable-symvers --with-gnu-ld --with-gnu-as --disable-isl-version-check --enable-checking=release --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC)

Zaita@Anubis MSYS ~
$ ./a.exe
Local = 0.0010370292068795884059
Local = 0.0010370292068795884059
Thread = 0.0010370292068795884059
Thread = 0.0010370292068795884059
Zaita commented 3 years ago

Upstream bug: https://sourceforge.net/p/mingw-w64/bugs/867/

Zaita commented 3 years ago

Update. This is fixed upstream. Do you have any plans to do a new release soon @jmeubank ?

jmeubank commented 3 years ago

The next TDM-GCC release will include the fix.

jmeubank commented 3 years ago

Fixed in TDM64 GCC 10.3.0.

C:\crossdev\tests>g++ -std=c++17 -O0 -g3 -Wall -o ThreadDoublePrecision.exe ThreadDoublePrecision.cpp

C:\crossdev\tests>ThreadDoublePrecision.exe
Local = 0.0010370292068795884059
Local = 0.0010370292068795884059
Thread = 0.0010370292068795884059
Thread = 0.0010370292068795884059