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

问题描述

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

看起来这个选项指定了某些线程API将被某些程序使用或图书馆,但通过什么?通过海湾合作委员会,libstdc ++或其他什么?



我发现这个:

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

解决方案

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



我必须强调这一点选项不禁止你编写任何你想要的代码(它对你可以在你的代码中调用的API有绝对的影响)。它只反映了GCC的运行时库(libgcc / libstdc ++ / ...)使用它们的功能。 @James引用的警告与GCC的内部线程模型无关,而与微软的CRT实现无关。总结:


  • posix :启用C ++ 11 / C11多线程功能。使libgcc依赖于libwinpthreads,因此即使不直接调用pthreads API,也会分发winpthreads DLL。在应用程序中分发多一个DLL没什么问题。



对任何调用Win32 API或pthread API的用户代码都没有影响。您可以随时使用两者。


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.

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?

I found this:Whats the difference between thread_posixs and thread_win32 in gcc port of windows?

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

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.

To summarize:

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

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

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

08-01 20:50