Skip to main content

Practice ยท 2 of 3

Publish with Release, Observe with Acquire

CHALLENGE
Difficulty: advanced+25 XP

ISO C11. Implement the publish pattern: void publish(atomic_int *flag, atomic_int *data, int payload) stores payload into data (relaxed), then stores 1 into flag (release). int observe(const atomic_int *flag, const atomic_int *data) loads flag with acquire; when it sees 1 it must see the payload โ€” return the data value, or -1 when flag is not yet 1.

Back to lesson: Practice: Atomics and Ordering Drills