mingw-w64 线程:posix 与 win32 [英] mingw-w64 threads: posix vs win32

查看:230
本文介绍了mingw-w64 线程:posix 与 win32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Windows 上安装 mingw-w64,有两个选项:win32 线程和 posix 线程.我知道 win32 线程和 pthreads 之间有什么区别,但我不明白这两个选项之间有什么区别.我怀疑如果我选择 posix 线程,它会阻止我调用 CreateThread 之类的 WinAPI 函数.

I'm installing mingw-w64 on Windows and there are two options: win32 threads and posix threads. I know what is the difference between win32 threads and pthreads but I don't understand what is the difference between these two options. I doubt that if I will choose posix threads it will prevent me from calling WinAPI functions like CreateThread.

这个选项似乎指定了某个程序或库将使用哪个线程 API,但是什么?通过 GCC、libstdc++ 或其他方式?

It seems that this option specify which threading API will be used by some program or library, but by what? By GCC, libstdc++ or by something else?

我发现了这个:有什么区别windows的gcc端口中的thread_posixs和thread_win32?

简而言之,对于这个版本的mingw,threads-posix release将使用posix API并允许使用std::thread,threads-win32将使用win32 API,并禁用std::thread标准的一部分.

In short, for this version of mingw, the threads-posix release will use the posix API and allow the use of std::thread, and the threads-win32 will use the win32 API, and disable the std::thread part of the standard.

好的,如果我选择 win32 线程,那么 std::thread 将不可用,但仍将使用 win32 线程.但用于什么?

Ok, if I will select win32 threads then std::thread will be unavailable but win32 threads will still be used. But used by what?

推荐答案

GCC 带有一个编译器运行时库 (libgcc),它用于(除其他外)为语言中的多线程相关功能提供低级操作系统抽象它支持.最相关的例子是 libstdc++ 的 C++11 ,它们没有当 GCC 是用它的内部 Win32 线程模型构建时,有一个完整的实现.MinGW-w64 提供了一个 winpthreads(在 Win32 多线程 API 之上的 pthreads 实现),然后 GCC 可以链接它以启用所有花哨的功能.

GCC comes with a compiler runtime library (libgcc) which it uses for (among other things) providing a low-level OS abstraction for multithreading related functionality in the languages it supports. The most relevant example is libstdc++'s C++11 <thread>, <mutex>, and <future>, which do not have a complete implementation when GCC is built with its internal Win32 threading model. MinGW-w64 provides a winpthreads (a pthreads implementation on top of the Win32 multithreading API) which GCC can then link in to enable all the fancy features.

我必须强调,此选项不会禁止您编写任何您想要的代码(它绝对没有影响您可以在代码中调用的 API).它仅反映 GCC 的运行时库 (libgcc/libstdc++/...) 用于其功能的内容.@James 引用的警告与 GCC 的内部线程模型无关,而是与 Microsoft 的 CRT 实现有关.

I must stress this option does not forbid you to write any code you want (it has absolutely NO influence on what API you can call in your code). It only reflects what GCC's runtime libraries (libgcc/libstdc++/...) use for their functionality. The caveat quoted by @James has nothing to do with GCC's internal threading model, but rather with Microsoft's CRT implementation.

总结:

  • posix:启用 C++11/C11 多线程特性.使 libgcc 依赖于 libwinpthreads,这样即使您不直接调用 pthreads API,您也会分发 winpthreads DLL.为您的应用程序再分发一个 DLL 并没有错.
  • win32:没有 C++11 多线程特性.
  • posix: enable C++11/C11 multithreading features. Makes libgcc depend on libwinpthreads, so that even if you don't directly call pthreads API, you'll be distributing the winpthreads DLL. There's nothing wrong with distributing one more DLL with your application.
  • win32: No C++11 multithreading features.

两者都不会影响调用 Win32 API 或 pthreads API 的任何用户代码.您可以随时使用两者.

Neither have influence on any user code calling Win32 APIs or pthreads APIs. You can always use both.

这篇关于mingw-w64 线程:posix 与 win32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆