1

1 つの Linux アプリケーションを Windows に移植しています。マルチスレッド部分で多くの変更を行う必要があることに気付きました。

Windowsでは、「pthread_t」(Linuxにある)と同等の構造は何ですか?

Windowsでは、「pthread_attr_t」(Linuxにある)の構造に相当するものは何ですか?

移植中のヒントを教えてください。

ありがとう...

4

2 に答える 2

1

The equivalent to pthread_t would be (as is so often the case) a HANDLE on Windows - which is what CreateThread returns.

There is no direct equivalent of pthread_attr_t. Instead, the attributes of a flag such as the stack size, whether the thread is initially suspended and other things are passed to CreateThread via arguments.

In the cases I saw so far, writing a small wrapper around pthreads so that you can have an alternative implementation for Windows was surprisingly simple. The most irritating thing for me was that on Windows, a Mutex is not the same thing as on Linux: on Windows, it's a handle which can be accessed from multiple processes. The thing which the pthread library calls mutex is called "critical section" on Windows.

That being said, if you find yourself finding more than just a few dozen lines of wrapper code you might want have a look at the c++11 thread library or at the thread support in Boost to avoid reinventing the wheel (and possibly wrongly so).

于 2013-08-07T07:15:42.017 に答える