"debut TD0"
This commit is contained in:
34
2019-2020/S3T_TP_07_THREADS/Demonstrations/ds_pthread.c
Normal file
34
2019-2020/S3T_TP_07_THREADS/Demonstrations/ds_pthread.c
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
int GlobV = 0;
|
||||
|
||||
void* action (void* increment) {
|
||||
for (i=1 ; i<= NOMBRE; i++) globV = globV + *increment;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int argc; char* argv[]) {
|
||||
pthread_t unThread;
|
||||
int valeur;
|
||||
assert (argc == 2);
|
||||
valeur = atoi(argv[1];
|
||||
|
||||
if (pthread_create(&unThread, NULL, action, &valeur) {
|
||||
perror("pthread_create");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
}
|
||||
printf("\nmain : globV = %d \n\n", globV) ;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user