13
votes

I just dipped my toes into the POSIX pond and tried out POSIX threads for the first time. Until now, I'd been under the impression that there's a big architectural difference between POSIX threads and Win32 threads, but from the (admittedly little) that I tried, I didn't really see any difference.

I'm still curious though -- what are the differences (if any) between POSIX threads and Win32 threads? Are they different fundamentally, or do they just have minor differences?

2
"Why Windows Threads are better than POSIX Threads": software.intel.com/en-us/blogs/2006/10/19/… Be sure to read the comments for an entertaining twist (unfortunately, the original source for the twist doesn't seem to be available anymore, but it's there in the comments). - Michael Burr
@MichaelBurr provocative title. The article have been discussed on reddit, by the way. - Hi-Angel

2 Answers

13
votes

There are huge differences between how threads are managed and scheduled "under the hood" in Windows NT family kernels and on many Unix kernels, but that's not the question.

If you're just talking about the interface (the services exposed by Win32 threads and POSIX threads), with some work you can almost map any POSIX thread feature to a Win32 equivalent ~1:1. And it has been done (see pthreads-win32).

One big difference I may notice is that under Win32 you use actual system calls to work with threads, instead POSIX threads' calls are part of a library (pthreads), that - under many Unix systems - calls some very low level system calls of Unix kernels (under Linux there's clone()).

Just to prove you that, unless you go very deep, pthreads is nothing so special, you can download pthreads-win32 that exposes quite the same interface of pthreads, and any function is mapped on Win32 thread APIs. And it works.

1
votes

One small but crucial difference seems to be that there's no POSIX equivalent to Windows's CREATE_SUSPENDED.