linux-sysprog · beginner · ~15 min

Useful thread count

Cap parallelism at the lesser of cores and tasks.

Challenge

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).

Starter code

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.