Hi Liu,

----- Original Message ----- 
From: "Liu Hao" <[email protected]>
To: <[email protected]>; "Maarten Verhage" 
<[email protected]>
Sent: Monday, December 17, 2018 03:43
Subject: Re: [Mingw-w64-public] win32 threads


>在 2018/12/17 2:58, Maarten Verhage 写道:
>> Hi all or dear people,
>>
>> Regarding the greeting please choose the one that best matches your
>> formality preference to which you view the mailing list members :)
>>
>> Alright, I would like to talk about the thread support of
>> x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0 as well as
>> x86_64-8.1.0-release-win32-seh-rt_v6-rev0
>>
>> On my Windows 7 computer, without any msys things, which I don't want to
>> use.
>>
>> So, the folder: 
>> path/to/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++
>> contains the header file "thread". It seems I have to define
>> _GLIBCXX_HAS_GTHREADS and _GLIBCXX_USE_C99_STDINT_TR1 to get the
>> implementation enabled. But I don't know if thats the right way to do it.
>>
>
> You have to use the `posix` thread model. The `win32` thread model does
> not define `_GLIBCXX_HAS_GTHREADS` due to incompleteness of support.
>

It's clear to me that although the files thread and mutex exist in the win32 
builds it is not possible to use C++11 thread functionality in these builds. 
It seems to me that the variants like posix-seh, win32-seh, win32-sjlj 
primary deal with how mingw64 and/or gcc are working internally than what it 
provides to the programming environment. I also discovered that I am able to 
write a little program using pthreads even in the win32-seh variant. Then I 
just link with -l:libwinpthread.a and the program does what I expected. 
using the command "llvm-readobj -coff-imports test.exe" I learned that it 
used functions like _beginthreadex of msvcrt.dll. I also tested when linking 
with -l:libwinpthread.dll.a and I think libwinpthread-1.dll in its turn uses 
the same thread functionality of msvcrt.dll right?

>> The thread header in turn include the file gthr.h located in:
>> path/to/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32/bits
>> but the implementation is commented out.
>>
>
> Hmm isn't it the one that merely declares `__gthr_*` interfaces, but not
> the one that actually defines them?
>
>> I was trying some very basic thread example code (attached.) to get it to
>> compile. But that doesn't seem to work (see result.txt)
>>
>> My questions are:
>>
>> 1) What does threading in the mingw64 win32 build variants actually 
>> offer?
>
> There are a few infrastructures:
> 1) C++11 requires initialization of local static objects to be
>   thread-safe. This is guaranteed using mutexex and condition
>   variables (IIRC the win32 does not have condition variables so it
>   suffers from the possbility of dead lock if the static constructor
>   spawns a new thread and waits for it to terminate thereafter).
> 2) The SJLJ exception model uses thread-local storage to track the top
>   of stack frames. Windows native TLS has no support of destructors so
>   it has to be implemented with emutls provided by GCC.
> 3) The GCC `__thread`, C11 `_Thread_local` and C++11 `thread_local`
>   requires the aforementioned TLS support. In reality MSVC implements
>   not only explicit TLS but implicit TLS [*] for this purpose, however
>   GCC has no support yet.
>
> [*] http://www.nynaeve.net/?p=183

This goes a bit over my head. Are you talking about how mingw64 itself or 
gcc is doing it's job? What I meant with my question as to what it offers is 
from the perspective of doing software development for windows using various 
mingw64 build variants. As you have all this knowledge as you've shown 
above. Would you be willing to connect the dots of these pieces of knowledge 
to present something that would assist in the decision making for a software 
developers viewpoint to which build variant to use like: win32-seh, 
win32-sjlj, posix-seh? For example do any of these builds have an influence 
of the threading used in the executables build with mingw64? And concerning 
the stability and performance of mingw64 library itself and the gcc that is 
included, what for effect has the decision of the build variant on these 
topics?

I would be sorry it this is somewhere easily found as documentation. I do 
realize this last one might be a big question. I would really appriciate if 
you are willing to clear this up for me and maybe for other people too.

Best regards,
Maarten Verhage 


_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to