简体   繁体   English

在windows build上使用pthread.h

[英]Using pthread.h on a windows build

I have a codebase that makes extensive use of pthread.h. 我有一个广泛使用pthread.h的代码库。 On a windows visual studio project, this obviously doesn't work since pthreads is a unix utility. 在windows visual studio项目中,这显然不起作用,因为pthreads是一个unix实用程序。

I know there exists pthread-win32 or something of the sort, but is there a way to have a codebase use this, without replacing all of the pthread code? 我知道存在pthread-win32或类似的东西,但有没有办法让代码库使用它,而不替换所有的pthread代码?

edit: I'd prefer to not have to go through and replace all the pthread calls. 编辑:我宁愿不必通过并替换所有的pthread调用。 This is my question 这是我的问题

Try http://sourceware.org/pthreads-win32/ . 试试http://sourceware.org/pthreads-win32/ While I've never used that particular library, I've had luck using some windows ports/abstraction layers of POSIX APIs. 虽然我从未使用过那个特定的库,但我很幸运使用了POSIX API的一些Windows端口/抽象层。

I would recommend boost as a library that contains a platform-independent thread abstraction. 我建议将boost作为一个包含独立于平台的线程抽象的库。 I don't think you'll find any attempt to call the pthread functions themselves to be satisfying. 我认为你不会发现任何试图将pthread函数称为满足的尝试。 It's also not very hard to map pthread to Win32 for yourself. 将pthread映射到Win32也不是很难。

If the code is very heavily *nix-based, you'll probably have the best luck compiling it with Cygwin +GCC. 如果代码非常基于* nix,那么使用Cygwin + GCC编译它可能会有最好的运气。 If pthreads is the only *nix dependency and you'd like to avoid the Cygwin dependency, then you should go with Pthreads-win32 . 如果pthreads是唯一的* nix依赖项,并且您希望避免Cygwin依赖项,那么您应该使用Pthreads-win32

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM