https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86155

            Bug ID: 86155
           Summary: std::thread
           Product: gcc
           Version: 8.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rebel at ameritech dot net
  Target Milestone: ---

Successful Compiler Build:
mingw-w64-v5.0.4:
../src/mingw-w64-libraries/winpthreads/configure --build=x86_64-w64-mingw32
--host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32
--prefix=/c/temp/gcc/dest/x86_64-w64-mingw32
--with-sysroot=/c/temp/gcc/dest/x86_64-w64-mingw32 --disable-shared

make -j4 -O all "CFLAGS=-s -O3"

 ../src/configure --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32
--target=x86_64-w64-mingw32 --disable-lib32
--prefix=/c/temp/gcc/dest/x86_64-w64-mingw32
--with-sysroot=/c/temp/gcc/dest/x86_64-w64-mingw32 --enable-wildcard

make -j4 -O all "CFLAGS=-s -O3"

gcc 8.1.0:
../src/configure --enable-languages=c,c++ --build=x86_64-w64-mingw32
--host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --disable-multilib
--prefix=/c/temp/gcc/dest --with-sysroot=/c/temp/gcc/dest
--disable-libstdcxx-pch --disable-libstdcxx-verbose --disable-nls
--disable-shared --disable-win32-registry --with-arch=native
--enable-threads=posix --enable-libgomp

 make -j4 -O S bootstrap "CFLAGS=-g0 -O3" "CXXFLAGS=-g0 -O3"
"CFLAGS_FOR_TARGET=-g0 -O3" "CXXFLAGS_FOR_TARGET=-g0 -O3" "BOOT_CFLAGS=-g0 -O3"
"BOOT_CXXFLAGS=-g0 -O3"


Windows 10 (sandybridge CPU) Mutli-threaded C++ program compiles with GCC8.1.1
but crashes with a segmentation fault.

Same program compiles and runs successfully with GCC7.3 and with gcc version
8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

test program source code:

#include <iostream>
#include <windows.h>
#include <thread>
#include <chrono>

void function_1()
{
    for (int i = 0; i != 4; i++)
    {
        std::cout << "Function 1 i = " 
                << i << std::endl;
        std::chrono::milliseconds(1000);
    }
}


void function_2()
{
    for (int j = 0; j != 4; j++)
    {
        std::cout << "                   Function 2 j = " 
                  << j << std::endl;
        std::chrono::milliseconds(500);
    }
}


int wmain()
{
        std::thread thread_1(function_1);
    std::thread thread_2(function_2);
    thread_1.join();
    thread_2.join();
    return 0;
}

Compiles with GCC 8.1.1 and GCC 7.3:
g++ -DUNICODE -D_DEBUG -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_DEPRECATE -O0 -Og
-ggdb -Wall -c -fmessage-length=0 -Wno-unknown-pragmas -o HelloWorld.o
"..\\HelloWorld.cpp" 
g++ -municode -mwindows -o thread.exe HelloWorld.o

When program runs successfully(GCC7.3)
Function 1 i = 0
Function 1 i = 1
Function 1 i = 2
Function 1 i = 3
                   Function 2 j = 0
                   Function 2 j = 1
                   Function 2 j = 2
                   Function 2 j = 3

When Program Crashes(GCC 8.1.1):
Segmentation fault

Reply via email to