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
|
void * monThread(void * arg){
... CODE DU THREAD ...
pthread_mutex_lock(&verrousParametre);
pthread_cond_signal(conditionParametre);
pthread_mutex_unlock(&verrousParametre);
}
int main(){
...
pthread_mutex_t verrous[4];
pthread_cond_t conditions[4];
for(int i = 0 ; i < 4; ++i){
pthread_mutex_init(&verrous[i], NULL);
pthread_cond_init(&conditions[i], NULL);
}
//Création de 4 threads avec pthread_create(), avec en paramètre un pthread_cond_t propre
for(int i = 0; i < 4; ++i) {
pthread_mutex_lock(&verrous[i]);
pthread_cond_wait(&conditions[i]);
pthread_cond_unlock(&verrous[i]);
}
} |
Partager