Visual Studio 2017,如何制作 #include <pthread.h>工作? [英] Visual Studio 2017, How to make #include &lt;pthread.h&gt; work?

查看:36
本文介绍了Visual Studio 2017,如何制作 #include <pthread.h>工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得我今天一直在寻找如何使 #include <pthread.h> 在 Windows 10 上的 Visual Studio 2017 中工作,但还没有找到答案已经工作了.有人可以请教我如何让它工作吗?

I feel like I've been searching for hours today on how to make #include <pthread.h> work in Visual Studio 2017 on Windows 10 and haven't come across an answer that has worked. Can someone please instruct me how to get this to work?

我收到的错误是:无法打开源文件pthread.h"

The error I receive is: cannot open source file "pthread.h"

推荐答案

Windows 本身不支持 pthread.

Windows doesn't natively support pthreads.

您可以使用 Windows 的 pthread 实现.如果您只是想尽快在 Windows 上运行一些代码,那么这可能是您最好的选择.

There is an implementation of pthreads for Windows you could use. If you're just trying to get some code running on Windows ASAP it may be your best bet.

如果你能修改代码,你可能想看看你实际使用的是什么pthread函数;如果您只需要一个互斥锁,那么在 pthreads/winapi 周围使用几个 #ifdef 可能是更好的方法.

If you can modify the code, you might want to take a look at what pthread functions you are actually using; if all you need is a mutex a few #ifdefs around pthreads/winapi may be a better way to go.

还有一些项目实现的兼容层不像完整的 pthreads API 那样具有表现力,但对于大多数项目来说已经足够了.TinyCThread 是一个实现 C11 的选项(我坚持,所以建议加一点盐)线程 API.

There are also some projects which implement compatibility layers that aren't as expressive as the full pthreads API, but are more than enough for most projects. TinyCThread is one option (which I maintain, so take the recommendation with a grain of salt) which implements the C11 threads API.

其他选项包括:

OpenMP 也是不错的选择.它真的很容易使用,但在更高级别上运行,因此可能需要更大量的重写.

OpenMP could also be a good choice. It is really easy to use, but operates at a higher level and so it may require a more substantial rewrite.

这篇关于Visual Studio 2017,如何制作 #include <pthread.h>工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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