Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #include <dirent.h>
- #include <sys/types.h>
- void *th_rt(void *arg);
- int MIN = -1;
- pthread_mutex_t MutexMIN = PTHREAD_MUTEX_INITIALIZER;
- int main(int argc, char const *argv[]){
- pthread_t tid[5];
- int i;
- if(argc < 6){
- printf("usage: ./a.out <dir> <dir> <dir> <dir> <dir> \n");
- return -1;
- }
- for(i=0;i<5;i++)
- pthread_create(&tid[i],NULL,th_rt,(void *)argv[i+1]);
- for(i=0;i<5;i++)
- pthread_join(tid[i],NULL);
- printf("Min: %d\n",MIN);
- return 0;
- }
- void *th_rt(void *arg){
- int counter=0;
- char *dirName;
- DIR *d;
- dirName = (char *)arg;
- d = opendir(dirName);
- while(readdir(d) != NULL)
- counter++;
- printf("%s - %d\n",dirName,counter);
- pthread_mutex_lock(&MutexMIN);
- if(counter < MIN || MIN == -1) MIN = counter;
- pthread_mutex_unlock(&MutexMIN);
- pthread_exit(NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement