Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*version thread */
- #include <stdlib.h>
- #include <stdio.h>
- #include <pthread.h>
- #include <math.h>
- #define LIMITE 1000000000
- void* maFonction(void* data);
- double tab[4];
- int main()
- {
- printf("VERSION MULTI THREAD avec n=1000000000\n\n");
- printf("");
- pthread_t thread0;// On crée un thread
- pthread_t thread1;// On crée un thread
- pthread_t thread2;// On crée un thread
- pthread_t thread3;// On crée un thread
- pthread_create(&thread0, NULL, maFonction, (void*)0);// Permet d'exécuter le fonction maFonction en parallèle
- pthread_create(&thread1, NULL, maFonction, (void*)1);// Permet d'exécuter le fonction maFonction en parallèle
- pthread_create(&thread2, NULL, maFonction, (void*)2);// Permet d'exécuter le fonction maFonction en parallèle
- pthread_create(&thread3, NULL, maFonction, (void*)3);// Permet d'exécuter le fonction maFonction en parallèle
- // Attend la fin des thread créés
- pthread_join(thread0, NULL);
- pthread_join(thread1, NULL);
- pthread_join(thread2, NULL);
- pthread_join(thread3, NULL);
- printf("La constante d'euler: %.10f\n\n", tab[0]+tab[1]+tab[2]+tab[3]-log(LIMITE)); return 0;
- }
- void* maFonction(void* data){
- double i,tmp,somme=0;
- int coef=(int)data;
- i=1+coef;
- while(i<LIMITE){
- tmp=(double)1/i;
- somme=somme+tmp;
- i+=4;
- }
- tab[coef]=somme;
- return 0;
- }
Add Comment
Please, Sign In to add comment