| 181 | |
| 182 | template<typename T> |
| 183 | static void AcquireReleaseThreadA(T id, T other_id, int iters, AtomicInt<T>* control, |
| 184 | T* payload) { |
| 185 | const int DELAY = 100; |
| 186 | for (int it = 0; it < iters; ++it) { |
| 187 | // Phase 1 |
| 188 | // (A-1) This store is not allowed to reorder with the below "store release". |
| 189 | *payload = it; |
| 190 | control->Store(other_id); |
| 191 | |
| 192 | // Phase 2 |
| 193 | while (control->Load() != id) ; |
| 194 | // (A-2) This store is not allowed to reorder with the above "load acquire". |
| 195 | *payload = -it; |
| 196 | |
| 197 | // Give thread B a chance to get started on Phase 1. |
| 198 | for (int i = 0; i < DELAY; ++i) { |
| 199 | AtomicUtil::CompilerBarrier(); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | template<typename T> |
| 205 | static void AcquireReleaseThreadB(T id, T other_id, int iters, AtomicInt<T>* control, |