在 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.

> 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


> 2) How should I modify my example code to get it to work with native Windows 
> threads? You know in a way that the resulting executable actually calls the 
> Windows API CreateThread function among others..
> 

It is not possible unless you use the `posix` thread model or use a
different standard library (e.g. libc++, compiled with `clang++
-stdlib=libc++`).

> 3) If this is not possible why do the headers like thread and mutex exist in 
> the mingw win32 thread builds?
> 

I have no idea. They might have been kept because there was no reason to
exclude them solely for this platform and GCC was not configured with
`--enable-threads=single`.


> Best regards,
> Maarten Verhage 
> 
> 
> 



-- 
Best regards,
LH_Mouse

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

Reply via email to