Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POSIX Threads vs. Win32 Threads

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?

like image 245
user541686 Avatar asked Apr 13 '11 05:04

user541686


People also ask

What is POSIX win threads for Windows?

POSIX Threads, commonly known as pthreads, is an execution model that exists independently from a language, as well as a parallel execution model. It allows a program to control multiple different flows of work that overlap in time.

Does Mingw support POSIX?

MinGW-w64 provides a development and runtime environment for 32- and 64-bit (x86 and x64) Windows applications using the Windows API and the GNU Compiler Collection (gcc). This package contains the C compiler, supporting cross-compiling to 64-bit MinGW-w64 targets, using the POSIX threading model.


2 Answers

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

like image 52
user541686 Avatar answered Oct 15 '22 18:10

user541686


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.

like image 41
gd1 Avatar answered Oct 15 '22 19:10

gd1