POSIX Threads

POSIX Threads, usually referred to as Pthreads, is a POSIX standard for threads. The standard, POSIX.1c, Threads extensions (IEEE Std 1003.1c-1995), defines an API for creating and manipulating threads.

The POSIX semaphore API works with POSIX threads but is not part of threads standard, having been defined in the POSIX.1b, Real-time extensions (IEEE Std 1003.1b-1993) standard. Consequently the semaphore procedures are prefixed by "sem_" instead of "pthread_".

This program creates five threads, each executing the function task_code that prints the unique number of this thread to standard output. If a programmer wanted the threads to communicate with each other, this would require defining a variable outside of the scope of any of the functions, making it a global variable.

Windows does not support the pthreads standard natively, therefore the Pthreads-w32 project seeks to provide a portable and open-source wrapper implementation. It can also be used to port Unix software (which use pthreads) with little or no modification to the Windows platform.[2] With some additional patches the last version 2.8.0 is compatible with 64-bit Windows systems.[3][4][5] 2.9.0 is said to also be 64-bit compatible.[6]

The mingw-w64 project also contains a wrapper implementation of pthreads, winpthreads,[7] which tries to use more native system calls than the Pthreads-w32 project.[8]