Capsules: compile-time lock discipline in OxCaml

In the previous post we fixed the racy gensym with Portable.Atomic . That worked because the shared state was a single integer with atomic primitives. What about state that needs a hash table, a multi-step update, or any structure where atomics aren’t enough? OxCaml’s answer is the capsule : a way to bundle state with its lock so the lock discipline becomes a type-checker job rather than a…