Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #include "src/functionX.h"
- void main(){
- // /*ouverture d'un fichier log */
- // open_log('a', NULL, NULL);
- /* déclaration de 8 threads */
- int numThreads = 2;
- pthread_t threads[numThreads];
- /* 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
- prototype: int pthread_create(pthread_t* thread, pthread_attr_t* attr, void*(*start_routine)(void*), void* arg); */
- int err, err2;
- int i;
- // int ii[3] = {1, 2, 3};
- err = pthread_create(&threads[0], NULL, functionX, (void *)1);
- err2 = pthread_create(&threads[1], NULL, functionX, (void *)2);
- err ? printf("Erreur dans la creation du thread 1!") : printf("Thread 1 cree avec succes");
- err2 ? printf("Erreur dans la creation du thread 2!") : printf("Thread 2 cree avec succes");
- // /* Attendre la fun du thread */
- // pthread_join(threads[numThreads], NULL);
- }
- void* functionX(void* it)
- {
- int i = 0;
- for(i; i < 60; i++)
- {
- printf("%d thread %d\n", i, *(int *)it);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement