François Trahay


fork() crée un nouveau process et duplique le processus
appelant
rax (qui stocke la valeur de
retour de fork)
Une autre manière de représenter un processus est de séparer le flux d’exécution et les ressources du processus


int pthread_create(pthread_t *thread,
const pthread_attr_t *attr,
void *(*start_routine) (void *),
void *arg);start_routine(arg)attr (in): attributs du thread à créerstart_routine (in): adresse de la fonction à exécuter
par le nouveau threadarg (in): paramètre à passer à la fonction
start_routinethread (out): identifiant du thread crééUn thread se termine quand
void pthread_exit(void* retval)void* thread_function(void* arg) {
...
if(...) {
...
pthread_exit(NULL); // fin du thread
}
...
return NULL; // fin de thread_function, donc destruction du thread
}
tid.*retvalAssure l’accès en exclusion mutuelle d’une section critique.
pthread_mutext_t lock;
pthread_mutext_init(&lock, NULL); // Initialise le verrou
pthread_mutext_lock(&lock); // Prend le verrou
counter++;
pthread_mutext_unlock(&lock); // Relache le verrou
pthread_mutext_destroy(&lock); // Détruit le verrou