linux-sysprog · beginner · ~15 min
Catch the resource-leak mistake.
Every joinable thread you forget to join leaks resources until the process exits. Count the forgotten ones.
Implement int forgotten_joins(int created, int joined) that returns how many joinable threads were never joined.
created: joinable threads created.joined: how many were joined.created - joined, floored at 0.
forgotten_joins(5, 3) -> 2
forgotten_joins(4, 4) -> 0
joined >= created: return 0.created: joinable threads created; joined: joined count.
created - joined, floored at 0.
Result is never negative.
int forgotten_joins(int created, int joined) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.