/odin-native:memory-modelfrom ODIN Native
Guides selection of C++ and Rust atomic memory orderings, reasoning about happens-before edges, lock-free patterns, and data race diagnosis.
Ships in ODIN Native. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Atomics without a memory ordering argument are guesses. The C++ and Rust models are the same model: pick the weakest ordering that proves the happens-before edge the algorithm needs, and justify it in a comment.
| Field | Bound contract |
|---|---|
| Trigger | The task selects memory_order values or Rust Orderings, explains a synchronization edge, writes lock-free code, or reads TSan output on a race. |
| Authority | Read-only. The skill explains and drafts; edits land through the normal coding path. No remote mutation. |
| Side effect | None. |
| Done | Every atomic operation in the reviewed code carries an ordering justified by the synchronization edge it creates, or a race is named with the edge that is missing. |
| Ordering | C++ | Rust | Guarantee |
|---|---|---|---|
| Relaxed | memory_order_relaxed | Ordering::Relaxed | Atomicity only, no ordering |
| Acquire | memory_order_acquire | Ordering::Acquire | No later read or write moves before this load |
| Release | memory_order_release | Ordering::Release | No earlier read or write moves after this store |
| AcqRel | memory_order_acq_rel | Ordering::AcqRel | Both, RMW operations only |
| SeqCst | memory_order_seq_cst | Ordering::SeqCst | One total order every thread agrees on |
std::atomic<int> data_ready{0};
int data = 0; // plain, guarded by the edge
void producer() {
data = 42; // 1) plain write
data_ready.store(1, std::memory_order_release); // 2) release
}
void consumer() {
while (!data_ready.load(std::memory_order_acquire)) {} // 3) acquire
assert(data == 42); // 4) guaranteed by the edge
}
| Pattern | Ordering |
|---|---|
| Statistics counter | Relaxed everywhere |
| Reference count | Relaxed on increment, AcqRel on the decrement that may free |
| Publish flag and data | Release on the store, Acquire on the load |
| Lock-free queue first cut | SeqCst, then weaken one edge at a time with a re-run of the tests |
| Sequence-number check | Release plus Acquire |
| Mutex internals | AcqRel on the RMW that takes and gives the lock |
// publish several writes, then flip the flag
data1 = 1;
data2 = 2;
std::atomic_thread_fence(std::memory_order_release);
flag.store(true, std::memory_order_relaxed);
// consumer pairs with an acquire fence after reading the flag
Keep SeqCst for the cases that need a single global order. Two flags each read after waiting on the other is the store-buffering case where weaker orderings allow both readers to miss both writes. Done when: the code either uses SeqCst on the participating operations or carries a written proof that weaker orderings suffice.
Map C++ orderings to Rust directly. The names change, the model does not. Done when: the review uses one vocabulary across both.
| C++ | Rust |
|---|---|
memory_order_relaxed | Ordering::Relaxed |
memory_order_acquire | Ordering::Acquire |
memory_order_release | Ordering::Release |
memory_order_acq_rel | Ordering::AcqRel, RMW only |
memory_order_seq_cst | Ordering::SeqCst |
atomic_thread_fence(order) | std::sync::atomic::fence(order) |
Rust signs the intent in the type: AtomicBool, AtomicUsize, and friends, with compare_exchange returning the previous value and the failure ordering taken explicitly.
compare_exchange_weak in retry loops, where spurious failure costs one iteration. Done when: every CAS call carries a legal ordering pair.int expected = 0;
while (!val.compare_exchange_weak(expected, 42,
std::memory_order_acq_rel, // success
std::memory_order_acquire)) {
expected = 0; // reset when the caller reuses the variable
}
Fold in the platform facts. x86 is TSO: stores drain in order, so plain Acquire and Release compile to plain loads and stores, and SeqCst needs a full fence or a locked operation. ARMv8 and RISC-V are weakly ordered: acquire and release map to load-acquire and store-release instructions, and a full fence needs an explicit barrier instruction. Done when: performance claims about ordering name the architecture.
Audit the classic mistakes. Done when: each row is checked against the code.
| Mistake | Fix |
|---|---|
| Relaxed used to publish data | Release on the store, Acquire on the load |
| SeqCst everywhere by fear | Keep SeqCst only where a total order is the argument; justify the rest |
| Plain reads of shared data beside atomics | The edge from the atomic pair must cover them, or the data must be atomic too |
volatile used for threads | volatile orders nothing across threads; use atomics |
| Two values assumed consistent with no edge between them | Add one atomic carrying the edge, or SeqCst on both |
| Lock-free pop frees nodes the readers still hold | Add a reclamation scheme; the ABA and reclamation problem is separate from ordering |
| Failure class | Behavior |
|---|---|
| TSan reports a race | One side of the pair is not atomic or the edge is missing. Name the two accesses, then supply the release and acquire pair that orders them. |
| Test passes but the reasoning is unclear | The ordering may be right by luck of the architecture. Write the edge as a comment and re-derive it, or weaken nothing. |
| Weakening SeqCst broke a stress test | Restore SeqCst for the participating operations; the code needed the total order. |
| CAS compile error on the failure ordering | The failure ordering was Release or AcqRel. Use Acquire or Relaxed. |
| Live lock in a CAS loop | The loop loses every race under contention. Add backoff or restructure to fewer writers. |
A per-site ordering review: each atomic operation, the edge it creates or needs, the chosen ordering, and the platform cost note where relevant. The happens-before diagram, the CAS variants, and the lock-free stack sketch are in references/cpp-memory-ordering.md.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub outlinedriven/odin-claude-plugin --plugin odin-native138 skills in this plugin
/abi-and-calling-conventionsUse when explaining System V AMD64, ARM AAPCS, RISC-V psABI, stack frames, variadic calls, or FFI register rules. Not for the Rust FFI binding layer: use rust-ffi./adc-dac-baremetalUse when configuring ADC sampling time, DMA-driven ADC, calibration, or DAC channel setup on bare-metal MCUs. Not for the DMA stream itself: use dma-baremetal./af-xdpUse when creating AF_XDP sockets, configuring UMEM and XSK rings, writing an XDP redirect program, or choosing copy versus zero-copy mode. Not for full kernel bypass: use dpdk.Other plugins' skills for the same job