Drive-by code-review, if you don’t mind. Don’t use memory_order_relaxed. Relaxed atomics almost never do what you want, and are only a performance gain on ARM and POWER (which probably isn’t worth the danger, anyway). You want memory_order_seq_cmp or whatever it is std::atomic calls it.