linux-sysprog · beginner · ~15 min
Name the common concurrency bugs.
Some patterns corrupt shared state or the runtime; thread-local state is inherently safe. Classify a described pattern as a concurrency bug or not.
Implement int is_concurrency_bug(const char *desc) that returns 1 if desc names a concurrency bug, else 0.
desc: a pattern name string.1 for "unguarded-shared-write", "double-unlock", "join-after-detach"; 0 for "thread-local-counter".
is_concurrency_bug("unguarded-shared-write") -> 1
is_concurrency_bug("double-unlock") -> 1
is_concurrency_bug("thread-local-counter") -> 0
desc: a pattern name string.
1 for the three buggy patterns, else 0.
Bugs: unguarded-shared-write, double-unlock, join-after-detach.
#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.