main.c 843 Bytes
#include <stdio.h>
#include <pthread.h>

void *print_hello(void *arg){
    (void) arg; // ici on utilise pas l'argument
    printf("Hello\n");
    pthread_exit(NULL);
}

void *print_nombre(void *arg){
    int n = *(int *) arg; // void* -> int* -> int
    printf("Le nombre est :%d:\n", n);
    pthread_exit(NULL);
}

int main(void){
    pthread_t tid1, tid2;
    // thread 1
    pthread_create(&tid1, NULL, print_hello, NULL);

    //thread 2
    int arg = 15;
    pthread_create(&tid2, NULL, print_nombre, (void *) &arg); // int -> int* -> void*

    // join thread 1
    pthread_join(tid1, NULL);
    printf("Thread 1 terminé\n");

    // join thread 2
    pthread_join(tid2, NULL);
    printf("Thread 2 terminé\n");

    printf("Je suis obligé de joindre les Threads pour les attendre en mode non-détaché\n");
    pthread_exit(NULL);
}