0ae69087
pfrison
Ajout des fichiers
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#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);
}
|