Understanding Rust concurrency and memory ordering
This is a medium-difficulty concurrency question that tests your grasp of how Rust's memory model enforces data-race freedom and what guarantees different synchronization primitives provide. It rewards deep familiarity with the visibility and ordering semantics that underpin safe concurrent code.
To reason through problems like this, you need to understand how threads communicate through shared state, what memory barriers are implicit in Rust's standard library, and how the compiler and CPU may reorder operations. The question isolates a specific pattern to test whether you can confidently predict which outcomes are actually possible—and rule out those that cannot occur.
- Happens-before relationships and memory ordering
- Atomics vs. mutexes: when each provides which guarantees
- Data-race freedom as a compile-time property
- Visibility across thread boundaries