1つのアトミック変数とstd::memory_order_seq_cst
を使用する場合、非アトミック操作の順序が変更されないことが保証されていますか?memory_order_seq_cstは非アトミック操作とどのように同期しますか?
私は
std::atomic<bool> quux = {false};
void foo() {
bar();
quux.store(true, std::memory_order_seq_cst);
moo();
}
を持っている場合たとえば、bar()
はstore
の呼び出し後に並べ替えを取得しないことが保証され、かつmoo()
はで、限り、私はstd::memory_order_seq_cst
を使用すると、store
の呼び出しの前に並べ替えを取得していません少なくとも別のスレッドの観点から?
また、別のスレッドから実行した場合、以下の仮定は有効ですか?
if(quux.load(std::memory_order_seq_cst) == true) {
// bar guaranteed to be called; its side-effects are visible
// moo might have been called, but is not guaranteed to
} else {
// bar might have been called, but is not guaranteed to
// moo might have been called, but is not guaranteed to
}
私はbar
もmoo
どちらもアトミック操作、ミューテックス、ロック、フェンスや他の同期機能を使用することを想定しています。
Nitpickingですが、cppreference.comは優れていますが、ISO規格ではありません。 – Zeta
@Zetaあなたは正しいです。私はcppreference.comがかなり正確であることを見つけましたが、それは標準のコピーではないので省略されているかもしれません。 –