linux-sysprog · beginner · ~15 min

Safe way to pass per-thread args

Recognise the shared-loop-variable thread-arg bug.

Challenge

Implement int arg_passing_safe(const char *how) returning 1 for "heap" or "unique-stack-slot" and 0 for "shared-loop-variable" (the classic bug where every thread sees the final loop value).

Starter code

#include <string.h>

int arg_passing_safe(const char *how) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.