Fix ParkingLot memory ordering bug
Summary: ``` auto x = std::atomic<std::uint64_t>{0}; auto y = std::atomic<std::uint64_t>{0}; // thread 1 x.store(1, std::memory_order_release); auto one = y.load(std::memory_order_seq_cst); // thread 2 y.fetch_add(1, std::memory_order_seq_cst); auto two = x.load(std::memory_order_seq_cst); ``` Here it is possible for both `one` and `two` to end up with the value `0`. The code in ParkingLot assumed that this would not be possible; and the counter used to track the number of waiters could get reordered with respect to loads around it. This diff adds a seq_cst fence to ensure unparking threads always sequence their stores before parking _before_ the counter load globally. Reviewed By: yfeldblum, ot Differential Revision: D28972810 fbshipit-source-id: 06eb6a2e6df6b00bf07ac8454a79257a5276e154
Showing
Please register or sign in to comment