Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <pthread.h>
  4.  
  5. #include "src/functionX.h"
  6.  
  7. void main(){
  8.  
  9. //    /*ouverture d'un fichier log */
  10. //     open_log('a', NULL, NULL);
  11.  
  12.     /* déclaration de 8 threads */
  13.     int numThreads = 2;
  14.     pthread_t threads[numThreads];
  15.  
  16.  
  17.     /* Execute une fonction de type "void* ma_fonction(void* data)" dans start_routine, tout le reste est à NULL pour avoir les paramètres par défaut
  18.     prototype: int pthread_create(pthread_t* thread, pthread_attr_t* attr, void*(*start_routine)(void*), void* arg); */
  19.     int err, err2;
  20.     int i;
  21. //    int ii[3] = {1, 2, 3};
  22.  
  23.     err = pthread_create(&threads[0], NULL, functionX, (void *)1);
  24.     err2 = pthread_create(&threads[1], NULL, functionX, (void *)2);
  25.  
  26.     err ? printf("Erreur dans la creation du thread 1!") : printf("Thread 1 cree avec succes");
  27.     err2 ? printf("Erreur dans la creation du thread 2!") : printf("Thread 2 cree avec succes");
  28.  
  29. //    /* Attendre la fun du thread */
  30. //     pthread_join(threads[numThreads], NULL);
  31.  
  32. }
  33.  
  34. void* functionX(void* it)
  35. {
  36.     int i = 0;
  37.  
  38.     for(i; i < 60; i++)
  39.     {
  40.         printf("%d thread %d\n", i, *(int *)it);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement