Is std::mutex sequentially consistent?

前端 未结 2 1023
情书的邮戳
情书的邮戳 2021-01-04 05:48

Say, I have two threads A and B writing to a global Boolean variables fA and fB respectively which are initially set to <

2条回答
  •  抹茶落季
    2021-01-04 06:25

    Is it possible to observe the modifications on fA and fB in different orders in different threads C and D?

    The basic idea of a lock "acquiring" the "released" state (and side effect history) of an unlock make that impossible: you promise to only access a shared object by acquiring the corresponding lock, and that lock will "synchronize" with all past modifications seen by the thread that did the unlock. So only one history, not only of lock-unlock operations, but of accesses to shared objects, can exist.

提交回复
热议问题