Update with threads.
All checks were successful
isspam build / build (push) Successful in 2m16s

This commit is contained in:
retoor 2024-12-04 23:10:45 +01:00
parent d07d5f88e1
commit 25818ef568
2 changed files with 10 additions and 10 deletions

BIN
isspam

Binary file not shown.

View File

@ -308,21 +308,21 @@ void analyze_file(char *path) {
printf("File doesn't exist: %s\n",path);
}
}
void * analyze_file_thread(void *path){
analyze_file((char *)path);
return NULL;
}
int main(int argc, char *argv[]) {
if (argc > 1) {
pthread_t *threads = (pthread_t *)malloc(argc * sizeof(pthread_t));
for (int i = 1; i < argc; i++) {
pid_t pid = fork();
if(!pid){
printf("File: %s\n", argv[i]);
analyze_file(argv[i]);
printf("\n");
return 0;
}
pthread_create(&threads[i-1],NULL,analyze_file_thread,(void *)argv[i]);
}
for(int i = 1; i < argc; i++){
pthread_join(threads[i-1],NULL);
}
free(threads);
return 0;
}
analyze(stdin);