linux-sysprog · beginner · ~10 min
Two parallel loops: spawn then join. Track all thread IDs.
Implement int run_n_threads(int n) that spawns n threads (each one just immediately returns), joins them all in order, and returns n on success. Return -1 if any pthread_create or pthread_join fails.
Real programs spawn a pool of threads, not one. Practice the spawn-loop + join-loop pattern.
#include <pthread.h>
int run_n_threads(int n) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.