std :: thread,posix线程和win32线程在MinGW-W64 [英] std::thread, posix threads, and win32 threads in MinGW-W64

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

问题描述

我使用MinGW_W64,我无法决定如何使用threading选项。我可以使用posix线程或win32线程。到目前为止,我一直在使用C ++ 11的std :: thread为我的线程(这需要posix threads选项),我真的很喜欢的接口做这样的事情。但是,我从多个来源读到posix线程明显比win32线程慢,性能是我的一个大问题。

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.

我的项目最终将是多平台,但现在我的主要开发机器运行Windows 7。

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

我的问题是:MinGW_W64的posix线程比win32线程慢?如果是这样,我将如何编写一个包装器,让我使用一个std ::线程的接口,但使用win32线程下(或发现这样的包装,如果有人已经写了一个)?

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)?

推荐答案

已经有一个轻量级的本地实现的std ::线程和同步原语为MinGW,在纯WINAPI中实现:
https://github.com/meganz/mingw-std-threads

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

它是一个只有头文件的lib,应该与任何版本的MinGW有正确的C ++ 11支持。

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

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

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