Can I get Unix's pthread.h to compile in Windows? Can I get Unix's pthread.h to compile in Windows? multithreading multithreading

Can I get Unix's pthread.h to compile in Windows?


pthread.h is a header for the Unix/Linux (POSIX) API for threads. A POSIX layer such as Cygwin would probably compile an app with #include <pthreads.h>.

The native Windows threading API is exposed via #include <windows.h> and it works slightly differently to Linux's threading.

Still, there's a replacement "glue" library maintained at http://sourceware.org/pthreads-win32/ ; note that it has some slight incompatibilities with MinGW/VS (e.g. see here).


As @Ninefingers mentioned, pthreads are unix-only. Posix only, really.

That said, Microsoft does have a library that duplicates pthreads:

Microsoft Windows Services for UNIX Version 3.5

Library Download


pthread.h isn't on Windows. But Windows has extensive threading functionality, beginning with CreateThread.

My advice is don't get caught looking at WinAPI through the lens of another system's API. These systems are different. It's like insisting on riding the Win32 bike with your comfortable Linux bike seat. Well, the seat might not fit right and in some cases it'll just fall off.

Threads pretty much work the same on different systems, you have ThreadPools and mutexes. Having worked with both pthreads and Windows threads, I can say the Windows threading offers quite a bit more functionality than pthread does.

Learning another API is pretty easy, just think in terms of the concepts (mutex, etc), then look up how to create one of those on MSDN.