https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101037
Bug ID: 101037 Summary: std::atomic_flag deadlock on Windows Product: gcc Version: 11.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: bjornsundin02 at gmail dot com Target Milestone: --- The attached preprocessed file is a "ping-pong" example where two threads take turns to wait for the other thread using a C++20 std::atomic_flag. I am fairly certain that the code is correct and should not hang. I tested the program on Linux (Ubuntu 21.04), where it works as expected every time. On Windows, with a build from https://winlibs.com/, it more often than not hangs. The program on Windows is compiled in exactly the same way as on Linux. The expected behavior is: the program exits within less than a second. The observed behavior is: sometimes the program exits within less than a second, but often it hangs without ever returning. Below is the complete compiler command and output: > g++ -v -save-temps -std=c++20 -pthread deadlock_debugging.cpp Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=c:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/11.1.1/lto-wrapper.exe OFFLOAD_TARGET_NAMES=nvptx-none Target: x86_64-w64-mingw32 Configured with: ../configure --prefix=/R/winlibs64_stage/inst_gcc-11-20210605/share/gcc --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --enable-offload-targets=nvptx-none --with-pkgversion='MinGW-W64 x86_64-posix-seh, built by Brecht Sanders' --with-tune=generic --enable-checking=release --enable-threads=posix --disable-sjlj-exceptions --disable-libunwind-exceptions --disable-serial-configure --disable-bootstrap --enable-host-shared --enable-plugin --disable-default-ssp --disable-rpath --enable-libstdcxx-pch --enable-libstdcxx-time=yes --disable-libstdcxx-debug --disable-version-specific-runtime-libs --with-stabs --disable-symvers --enable-languages=c,c++,fortran,lto,objc,obj-c++ --disable-gold --disable-nls --disable-stage1-checking --disable-win32-registry --disable-multilib --enable-ld --enable-libquadmath --enable-libada --enable-libssp --enable-libstdcxx --enable-lto --enable-fully-dynamic-string --enable-libgomp --enable-graphite --enable-mingw-wildcard --with-mpc=/d/Prog/winlibs64_stage/custombuilt --with-mpfr=/d/Prog/winlibs64_stage/custombuilt --with-gmp=/d/Prog/winlibs64_stage/custombuilt --with-isl=/d/Prog/winlibs64_stage/custombuilt --enable-install-libiberty --enable-__cxa_atexit --without-included-gettext --with-diagnostics-color=auto --enable-clocale=generic --with-libiconv --with-system-zlib --with-build-sysroot=/R/winlibs64_stage/gcc-11-20210605/build_mingw/mingw-w64 CFLAGS=-I/d/Prog/winlibs64_stage/custombuilt/include/libdl-win32 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.1.1 20210605 (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++20' '-pthread' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-' c:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/11.1.1/cc1plus.exe -E -quiet -v -iprefix c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/11.1.1/ -D_REENTRANT -U_REENTRANT deadlock_debugging.cpp -mtune=generic -march=x86-64 -std=c++20 -fpch-preprocess -o a-deadlock_debugging.ii ignoring duplicate directory "c:/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../include/c++/11.1.1" ignoring duplicate directory "c:/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../include/c++/11.1.1/x86_64-w64-mingw32" ignoring duplicate directory "c:/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../include/c++/11.1.1/backward" ignoring duplicate directory "c:/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/11.1.1/include" ignoring nonexistent directory "R:/winlibs64_stage/inst_gcc-11-20210605/share/gcc/include" ignoring nonexistent directory "/R/winlibs64_stage/inst_gcc-11-20210605/share/gcc/include" ignoring duplicate directory "c:/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/11.1.1/include-fixed" ignoring duplicate directory "c:/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../x86_64-w64-mingw32/include" ignoring nonexistent directory "/mingw/include" #include "..." search starts here: #include <...> search starts here: c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../include/c++/11.1.1 c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../include/c++/11.1.1/x86_64-w64-mingw32 c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../include/c++/11.1.1/backward c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/11.1.1/include c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../include c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/11.1.1/include-fixed c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../x86_64-w64-mingw32/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++20' '-pthread' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-' c:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/11.1.1/cc1plus.exe -fpreprocessed a-deadlock_debugging.ii -quiet -dumpdir a- -dumpbase deadlock_debugging.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -std=c++20 -version -o a-deadlock_debugging.s GNU C++20 (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) version 11.1.1 20210605 (x86_64-w64-mingw32) compiled by GNU C version 11.1.1 20210605, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++20 (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) version 11.1.1 20210605 (x86_64-w64-mingw32) compiled by GNU C version 11.1.1 20210605, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 15f4039a47217655d2f44ccd07e6db0b COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++20' '-pthread' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-' c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../x86_64-w64-mingw32/bin/as.exe -v -o a-deadlock_debugging.o a-deadlock_debugging.s GNU assembler version 2.36.1 (x86_64-w64-mingw32) using BFD version (Binutils for MinGW-W64 x86_64, built by Brecht Sanders) 2.36.1 COMPILER_PATH=c:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/11.1.1/;c:/mingw64/bin/../libexec/gcc/;c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../x86_64-w64-mingw32/bin/ LIBRARY_PATH=c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/;c:/mingw64/bin/../lib/gcc/;c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../x86_64-w64-mingw32/lib/../lib/;c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../lib/;c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../x86_64-w64-mingw32/lib/;c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../ COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++20' '-pthread' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a.' c:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/11.1.1/collect2.exe -plugin c:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/11.1.1/liblto_plugin.dll -plugin-opt=c:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/11.1.1/lto-wrapper.exe -plugin-opt=-fresolution=a.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -m i386pep -Bdynamic c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/crtbegin.o -Lc:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1 -Lc:/mingw64/bin/../lib/gcc -Lc:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../x86_64-w64-mingw32/lib/../lib -Lc:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../lib -Lc:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/../../../../x86_64-w64-mingw32/lib -Lc:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/../../.. a-deadlock_debugging.o -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lkernel32 -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lkernel32 c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.1.1/crtend.o COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++20' '-pthread' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a.'