gpt4 book ai didi

windows - mingw-w64 线程 : posix vs win32

转载 作者:可可西里 更新时间:2023-11-01 11:53:50 36 4
gpt4 key购买 nike

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

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

我发现了这个: Whats the difference between thread_posixs and thread_win32 in gcc port of windows?

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 线程。但是用什么?

最佳答案

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

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

总结:

  • posix : 启用 C++11/C11 多线程功能。使 libgcc 依赖于 libwinpthreads,这样即使您不直接调用 pthreads API,您也会分发 winpthreads DLL。在您的应用程序中再分发一个 DLL 没有错。
  • win32 : 没有 C++11 多线程特性。

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

关于windows - mingw-w64 线程 : posix vs win32,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17242516/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com