#include <stdio.h> #include <pthread.h> #include <semaphore.h> #include <unistd.h> #include <stdlib.h> #define N 10 // nombre de threads void* f(void* args){ char* nom = (char*) args; sleep((rand() % 100) * 0.05); printf("%s: phase1\n", nom); sleep((rand() % 100) * 0.05); printf("%s: phase2 \n", nom); return NULL; } int main() { srand(time(NULL)); char noms[N][2] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"}; // noms des threads pthread_t t[N]; for (int i = 0; i < N; i +=1){ pthread_create(&t[i], NULL, f, (void*) noms[i]); } for (int i = 0; i < N; i +=1){ pthread_join(t[i], NULL); } return 0; }