linux-sysprog · beginner · ~15 min

Classify a threading bug

Name the common concurrency bugs.

Challenge

Some patterns corrupt shared state or the runtime; thread-local state is inherently safe. Classify a described pattern as a concurrency bug or not.

Task

Implement int is_concurrency_bug(const char *desc) that returns 1 if desc names a concurrency bug, else 0.

Input

  • desc: a pattern name string.

Output

1 for "unguarded-shared-write", "double-unlock", "join-after-detach"; 0 for "thread-local-counter".

Example

is_concurrency_bug("unguarded-shared-write")   ->   1
is_concurrency_bug("double-unlock")            ->   1
is_concurrency_bug("thread-local-counter")     ->   0

Input format

desc: a pattern name string.

Output format

1 for the three buggy patterns, else 0.

Constraints

Bugs: unguarded-shared-write, double-unlock, join-after-detach.

Starter code

#include <string.h>

int is_concurrency_bug(const char *desc) {
    /* TODO */
    return 0;
}

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