std::thread, posix threads, and win32 threads in MinGW-W64

天涯浪子 提交于 2019-12-12 09:06:10

问题


I'm using MinGW_W64, and I'm having trouble deciding how to move forward with the "threading" option. I can use either posix threads, or win32 threads. So far I've been using C++11's "std::thread" for my threading (which requires the posix threads option), and I really like the interface doing things this way. However, I've read from multiple sources that posix threads are significantly slower than win32 threads, and performance is a big concern for me.

My project will eventually be multi-platform, but for now my primary development machine is running Windows 7.

My question is: Are MinGW_W64's posix threads slower than the win32 threads? If so, how would I go about writing a wrapper that would let me using an std::thread-like interface but using win32 threads under the hood (or finding such a wrapper if someone's already written one)?


回答1:


There is already a lightweight native implementation of std::thread and sync primitives for MinGW, implemented in pure WINAPI: https://github.com/meganz/mingw-std-threads

It's a header-only lib and should work with any version of MinGW that has proper C++11 support.



来源:https://stackoverflow.com/questions/25276982/stdthread-posix-threads-and-win32-threads-in-mingw-w64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!