Reputation: 29
I am porting one Linux Application to Windows. I observed many changes need to be done in multithreading part.
what will be the equivalent structure for "pthread_t" (which is in Linux), in windows?
what will be the equivalent for structure for "pthread_attr_t" (which is in Linux), in windows?
Can you please guide me some tips while porting.
Thanks...
Upvotes: 1
Views: 2475
Reputation: 94549
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).
Upvotes: 1
Reputation: 509
Here is your tip - "pthread is POSIX".
Mingw has pthreads, Cygwin have pthreads and so on.
My advice is to stick with mingw and try not to do any changes.
Upvotes: 0