linux-sysprog · beginner · ~15 min
Cap parallelism at the lesser of cores and tasks.
Spawning more threads than work or cores wastes resources. Implement int useful_threads(int cores, int tasks) returning min(cores, tasks) (0 if either is <= 0).
int useful_threads(int cores, int tasks) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.