b'\n_START_ARTICLE_\nPosix threads\n_START_PARAGRAPH_\nPOSIX Threads, obvykle ozna\xc4\x8dov\xc3\xa1n jako Pthreads, je POSIXov\xc3\xbd standard pro vl\xc3\xa1kno (thread).  Standard, POSIX.1c, Threads roz\xc5\xa1\xc3\xad\xc5\x99en\xc3\xad (IEEE Std 1003.1c-1995), definuje API pro vytv\xc3\xa1\xc5\x99en\xc3\xad a manipulaci s vl\xc3\xa1kny._NEWLINE_Implementace API je mo\xc5\xben\xc3\xa1 na mnoh\xc3\xbdch Unix-like opera\xc4\x8dn\xc3\xadch syst\xc3\xa9mech podporuj\xc3\xadc\xc3\xadch POSIX jako nap\xc5\x99. FreeBSD, NetBSD, OpenBSD, GNU/Linux (projekt NPTL), Mac OS X, Solaris, DR-DOS a implementace pro Microsoft Windows tak\xc3\xa9 existuje za pou\xc5\xbeit\xc3\xad podsyst\xc3\xa9mu SFU/SUA, kter\xc3\xbd poskytuje nativn\xc3\xad implementaci n\xc4\x9bkolika POSIX API, pop\xc5\x99. tak\xc3\xa9 p\xc5\x99i vyu\xc5\xbeit\xc3\xad bal\xc3\xad\xc4\x8dk\xc5\xaf t\xc5\x99et\xc3\xad strany pthreads-w32, kter\xc3\xbd implementuje pthreads na vrcholu st\xc3\xa1vaj\xc3\xadc\xc3\xadch Windows API.\n_START_SECTION_\nP\xc5\x99\xc3\xadklad\n_START_PARAGRAPH_\nP\xc5\x99\xc3\xadklad ukazuj\xc3\xadc\xc3\xad pou\xc5\xbeit\xc3\xad Pthreads v jazyce C:_NEWLINE_#include <pthread.h>#include <stdio.h>#include <stdlib.h>#include <assert.h>_NEWLINE_ _NEWLINE_#define NUM_THREADS     5_NEWLINE_ _NEWLINE_void *TaskCode(void *argument){_NEWLINE_   int tid;_NEWLINE_ _NEWLINE_   tid = *((int *) argument);_NEWLINE_   printf("Ahoj sv\xc4\x9bte! To jsem j\xc3\xa1, vl\xc3\xa1kno %d!\\n", tid);_NEWLINE_ _NEWLINE_   /* Zde je mo\xc5\xbenost vlo\xc5\xbeit u\xc5\xbeite\xc4\x8dn\xc3\xa9 v\xc4\x9bci :-) */_NEWLINE_ _NEWLINE_   return NULL;}_NEWLINE_ _NEWLINE_int main(void){_NEWLINE_   pthread_t threads[NUM_THREADS];_NEWLINE_   int thread_args[NUM_THREADS];_NEWLINE_   int rc, i;_NEWLINE_ _NEWLINE_   /* vytvo\xc5\x99en\xc3\xad v\xc5\xa1ech vl\xc3\xa1ken */_NEWLINE_   for (i=0; i<NUM_THREADS; ++i) {_NEWLINE_      thread_args[i] = i;_NEWLINE_      printf("Ve fci main: vytv\xc3\xa1\xc5\x99en\xc3\xad vl\xc3\xa1kna %d\\n", i);_NEWLINE_      rc = pthread_create(&threads[i], NULL, TaskCode, (void *) &thread_args[i]);_NEWLINE_      assert(0 == rc);_NEWLINE_   }_NEWLINE_ _NEWLINE_   /* \xc4\x8dek\xc3\xa1n\xc3\xad na dokon\xc4\x8den\xc3\xad v\xc5\xa1ech vl\xc3\xa1ken */_NEWLINE_   for (i=0; i<NUM_THREADS; ++i) {_NEWLINE_      rc = pthread_join(threads[i], NULL);_NEWLINE_      assert(0 == rc);_NEWLINE_   }_NEWLINE_ _NEWLINE_   exit(EXIT_SUCCESS);}_NEWLINE_Tento program vytv\xc3\xa1\xc5\x99\xc3\xad 5 vl\xc3\xa1ken, ka\xc5\xbed\xc3\xa9 spou\xc5\xa1t\xc3\xad funkci TaskCode, kter\xc3\xa1 vypisuje unik\xc3\xa1tn\xc3\xad \xc4\x8d\xc3\xadslo dan\xc3\xa9ho vl\xc3\xa1kna do standardn\xc3\xadho v\xc3\xbdstupu. Pokud program\xc3\xa1tor chce, aby vl\xc3\xa1kna mezi sebou komunikovala, vy\xc5\xbeadovalo by to definov\xc3\xa1n\xc3\xad glob\xc3\xa1ln\xc3\xad prom\xc4\x9bnn\xc3\xa9 a o\xc5\xa1et\xc5\x99en\xc3\xad soub\xc4\x9bhu.\n_START_SECTION_\nPOSIX vl\xc3\xa1kna pro Windows\n_START_PARAGRAPH_\nWindows nativn\xc4\x9b nepodporuje standard pthreads, proto se projekt Pthreads-w32 sna\xc5\xbe\xc3\xad poskytnout p\xc5\x99enosnou open-source implementaci. S malou nebo \xc5\xbe\xc3\xa1dnou modifikac\xc3\xad mohou b\xc3\xbdt tak\xc3\xa9 pou\xc5\xbeity Unix programy (kter\xc3\xa9 vyu\xc5\xbe\xc3\xadvaj\xc3\xad pthreads) do platformy Windows. Posledn\xc3\xad verze 2.8.0 je kompatibiln\xc3\xad s 64-bit syst\xc3\xa9my Windows._NEWLINE_Interix \xe2\x80\x93 prost\xc5\x99ed\xc3\xad dostupn\xc3\xa9 ve Windows Services pro UNIX/Subsystem pro aplikace zalo\xc5\xbeen\xc3\xa9 na UNIXu. Bal\xc3\xad\xc4\x8dek poskytuje nativn\xc3\xad port pthreads API, tj. nenamapov\xc3\xa1no na Win32/Win64 API ale vytvo\xc5\x99en p\xc5\x99\xc3\xadmo v opera\xc4\x8dn\xc3\xadm syst\xc3\xa9mu "syscall" rozhran\xc3\xad.'