|
17 | 17 | #define MAX_TITLE 512 |
18 | 18 | #define MAX_SOURCE 32 |
19 | 19 | #define TITLE_WRAP 50 // preferred width for title column |
| 20 | +#define MAX_THREADS 64 |
| 21 | +#define MAX_THREADS (int)(sizeof(threads)/sizeof(threads[0])) |
20 | 22 |
|
21 | 23 | typedef struct { |
22 | 24 | char source[MAX_SOURCE]; |
@@ -344,17 +346,35 @@ int main(int argc, char *argv[]) { |
344 | 346 | int num_threads = 0; |
345 | 347 | pthread_t threads[64]; |
346 | 348 |
|
347 | | - // CSV threads |
348 | | - for (int i = 0; i < (int)(sizeof(exploitDBPaths)/sizeof(exploitDBPaths[0])); i++) |
349 | | - pthread_create(&threads[num_threads++], NULL, load_csv_thread, (void*)exploitDBPaths[i]); |
350 | | - |
351 | | - // Directory threads |
352 | | - for (int i = 0; i < (int)(sizeof(exploitDirs)/sizeof(exploitDirs[0])); i++) |
353 | | - pthread_create(&threads[num_threads++], NULL, scan_dir_thread, (void*)exploitDirs[i]); |
354 | | - |
355 | | - // Join all threads |
356 | | - for (int i = 0; i < num_threads; i++) |
357 | | - pthread_join(threads[i], NULL); |
| 349 | + // CSV threads |
| 350 | + for (int i = 0; i < (int)(sizeof(exploitDBPaths)/sizeof(exploitDBPaths[0])); i++) { |
| 351 | + if (num_threads >= MAX_THREADS) break; |
| 352 | + int rc = pthread_create(&threads[num_threads], NULL, load_csv_thread, (void*)exploitDBPaths[i]); |
| 353 | + if (rc != 0) { |
| 354 | + fprintf(stderr, "pthread_create failed for CSV path %s: %d\n", exploitDBPaths[i], rc); |
| 355 | + } else { |
| 356 | + num_threads++; |
| 357 | + } |
| 358 | + } |
| 359 | + |
| 360 | + // Directory threads |
| 361 | + for (int i = 0; i < (int)(sizeof(exploitDirs)/sizeof(exploitDirs[0])); i++) { |
| 362 | + if (num_threads >= MAX_THREADS) break; |
| 363 | + int rc = pthread_create(&threads[num_threads], NULL, scan_dir_thread, (void*)exploitDirs[i]); |
| 364 | + if (rc != 0) { |
| 365 | + fprintf(stderr, "pthread_create failed for dir %s: %d\n", exploitDirs[i], rc); |
| 366 | + } else { |
| 367 | + num_threads++; |
| 368 | + } |
| 369 | + } |
| 370 | + |
| 371 | + // Join exactly the created threads |
| 372 | + for (int i = 0; i < num_threads; i++) { |
| 373 | + int rc = pthread_join(threads[i], NULL); |
| 374 | + if (rc != 0) { |
| 375 | + fprintf(stderr, "pthread_join failed on thread %d: %d\n", i, rc); |
| 376 | + } |
| 377 | + } |
358 | 378 |
|
359 | 379 | display_results(); |
360 | 380 | pthread_mutex_destroy(&lock); |
|
0 commit comments