pthreads-win32 在各种 Windows 编译器上的可移植性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2797690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:25:36  来源:igfitidea点击:

Portability of pthreads-win32 over various windows compilers

windowsvisual-c++pthreadspthreads-win32

提问by Artyom

I'm using pthreads-win32 to allow threading support for windows.

我正在使用 pthreads-win32 来允许对 Windows 的线程支持。

I have a cross platform project that uses pthreads and I want to make it work on windows with various compilers and different OS versions.

我有一个使用 pthreads 的跨平台项目,我想让它在具有各种编译器和不同操作系统版本的 Windows 上工作。

At least, according to the documentation pthreads-win32 should work with MSVC and even MSVC builds provided.

至少,根据文档 pthreads-win32 应该与 MSVC 甚至提供的 MSVC 构建一起使用。

But I don't know if the library is tested with latest MSVC compilers like MSVC-2008 and if it is supported under 64bit windows.

但我不知道该库是否使用最新的 MSVC 编译器(如 MSVC-2008)进行了测试,以及它是否在 64 位 Windows 下受支持。

From Your own experienceare you aware of any issues with this library?

根据您自己的经验,您是否知道该库有任何问题?

  • Any issues with MSVC8, MSVC9, MSVC10?
  • Any issues with Windows x86_64?
  • Any issues with Windows Vista/Windows 7?
  • MSVC8、MSVC9、MSVC10 有什么问题吗?
  • Windows x86_64 有什么问题吗?
  • Windows Vista/Windows 7 有什么问题吗?

Notes:

笔记:

  • Do not even try to recommend using Boost.Thread, I'm not interested in. And I'm familiar with Boost.Thread library
  • I'm not interested in reinventing the Wheel with Win32 API (that lacks RW-Locks, Conditional Variables, etc).
  • I did managed to compile a projects with MSVC-2008 and MinGW GCC-4.3 and then run unit tests on it easily, using current pre-compiled DLL of pthreads.
  • 甚至不要尝试推荐使用 Boost.Thread,我不感兴趣。我熟悉 Boost.Thread 库
  • 我对用 Win32 API(缺少 RW-Locks、条件变量等)重新发明轮子不感兴趣。
  • 我确实设法用 MSVC-2008 和 MinGW GCC-4.3 编译了一个项目,然后使用当前预编译的 pthreads DLL 轻松地对其运行单元测试。

I just need to know limitations of pthreads-win32.

我只需要知道 pthreads-win32 的限制。

采纳答案by puffadder

Well, paxdiablohas apparently summed it up here. But from my past experience with this library, I can add a couple of things here.

好吧,paxdiablo显然已经在这里总结了。但是根据我过去使用这个库的经验,我可以在这里添加一些东西。

Firstly, I had used a subset of the library's functions with MSVC 2008 without any problems whatsoever.

首先,我在 MSVC 2008 中使用了库函数的一个子集,没有任何问题。

Secondly, some of my colleagues have got it going on the x86_64 (with MSVC2008 and MinGW). They haven't faced any issue either after many a cycles of beta and QA testing. Though I haven't tested it myself so can't be very sure on this one.

其次,我的一些同事已经在 x86_64(使用 MSVC2008 和 MinGW)上进行了操作。经过多次 Beta 和 QA 测试周期后,他们也没有遇到任何问题。虽然我自己没有测试过,所以不能很确定这个。

So by the looks of the things, it might be fit for use. The only caveat here is that if you find any issue you will be at the mercy of a not-so active mailing list (or perhaps you may want to get your hands dirty with the source code or something like that).

因此,从外观上看,它可能适合使用。这里唯一的警告是,如果您发现任何问题,您将受到不那么活跃的邮件列表的支配(或者您可能想接触源代码或类似的东西)。

回答by paxdiablo

Can't say for certain and this may not be what you want to hear but, given that the last release is dated 2006, I'd be very wary of using this in the latest compilers. It maywork but it's probably going to be up to you to get it going. There seems to be a lot of discussion about getting it working in Cygwin and MinGW but precious little for MSVC, and nothingI can find beyond MSVC2005.

不能肯定,这可能不是您想听到的,但是,鉴于最后一个版本的日期是2006 年,我会非常谨慎地在最新的编译器中使用它。它可能会起作用,但可能要靠您来实现。似乎有很多关于让它在 Cygwin 和 MinGW 中工作的讨论,但对于 MSVC 来说却很少,除了 MSVC2005 我找不到任何东西

Also, if you examine the CVS archives, there are precious few files that have been updated in the last year (most are two to five years ago). The couple that are dated less than a year ago have the description "Comments and code style changes" which leads me to believe none of the meat of the product has been under active development for a while.

此外,如果您检查 CVS 档案,去年更新的文件很少(大多数是两到五年前)。约会不到一年的那对夫妇的描述是“评论和代码样式更改”,这让我相信产品的任何内容都没有经过一段时间的积极开发。

Now maybe I'm wrong and this is just an incredibly well-written, stable product but my inner nature is more likely to conclude it's one of the bazillions of good ideas that have gone by the wayside.

现在也许我错了,这只是一个写得非常好的、稳定的产品,但我的内在本性更有可能得出结论,它是无数被搁置的好主意之一。

And, having a look at the mailing lists, there are only seven messages posted in the first five months of 2010 (the earliest of which has been unanswered for four months) and only 59 for the whole of 2009. Colour me sceptical but that doesn't seem like a massively vibrant support community.

而且,看看邮件列表,2010 年前五个月只发布了 7 条消息(最早的 4 个月没有回复),2009 年全年只有 59 条。让我怀疑,但事实并非如此看起来不像是一个非常活跃的支持社区。

There seems to be a patch for 64-bit Windows (see herein the 2010 archives) but, again, this appears to have problems which are unanswered since February and it only mentions support for MinGW:

似乎有一个适用于 64 位 Windows 的补丁(参见2010 年档案中的此处),但同样,这似乎存在自 2 月以来未得到解答的问题,并且仅提及对 MinGW 的支持:

... this patch (a bit rough and need some final cleaning up and some extension to the test run makefile for allowing CROSS here) enables pthread to be build for the x86_64-pc-mingw32 target.

...这个补丁(有点粗糙,需要一些最后的清理和一些测试运行 makefile 的扩展以允许 CROSS 在这里)允许为 x86_64-pc-mingw32 目标构建 pthread。

This is notthe sort of thing I'd be using for my mission-critical software.

不是我将用于我的关键任务软件的那种东西。

And I know you stated that you're not interested in re-inventing the wheel but you can implement multi-reader locks and condition variables from the more basic primitives quite easily - I even had a multi-reader scheme that solved the write starvation problem in a way that almost got me a patent (not that I agree with software patents but my employer insists they're valuable).

我知道你说过你对重新发明轮子不感兴趣,但你可以很容易地从更基本的原语中实现多读者锁和条件变量——我什至有一个多读者方案来解决写饥饿问题以一种几乎让我获得专利的方式(不是我同意软件专利,但我的雇主坚持认为它们很有价值)。

And if the only wheel you have has half its spokes missing and is horribly bent out of shape, you may just need to reconsider :-)

如果你唯一的车轮有一半的辐条丢失并且严重弯曲变形,你可能只需要重新考虑:-)

In any case, Vista and Server2k8 introduced both condition variablesand slim reader/writer locks. Thread-local storagehas been around since Win2k. I know that won't help if you still need to support XP but I'd be looking to the future.

无论如何,Vista 和 Server2k8 都引入了条件变量细长的读写器锁线程本地存储从 Win2k 开始就出现了。我知道如果您仍然需要支持 XP,那将无济于事,但我会展望未来。

And since you seem to have defined portability as "Windows-only", and all the features you want are available in the current versions, I'm not sure I see an advantage to sticking with pthreads. If you wanted portability to POSIX, yes, but that doesn't seem to be the case here.

而且由于您似乎已将可移植性定义为“仅限 Windows”,并且您想要的所有功能都在当前版本中可用,因此我不确定我是否看到坚持使用 pthread 的优势。如果您希望可移植到 POSIX,是的,但这里似乎并非如此。

回答by Puppy

Surprised that nobody has suggested Intel's Thread Building Blocks. They're very active and support virtually everything, with the newest release being less than two weeks ago, and C++0x features if you use a compliant compiler.

令人惊讶的是,没有人建议使用英特尔的线程构建块。它们非常活跃,几乎支持所有内容,最新版本是在不到两周前发布的,如果您使用兼容的编译器,还可以使用 C++0x 功能。

http://software.intel.com/en-us/intel-tbb/#sysreq

http://software.intel.com/en-us/intel-tbb/#sysreq