chenBright commented on code in PR #3539:
URL: https://github.com/apache/brpc/pull/3539#discussion_r3998908107


##########
src/bthread/parking_lot.h:
##########
@@ -69,13 +105,23 @@ class BAIDU_CACHELINE_ALIGNMENT ParkingLot {
             // Fast path, no need to futex_wait.
             return;
         }
-        if (_no_signal_when_no_waiter) {
-            _waiter_num.fetch_add(1, butil::memory_order_relaxed);
+        if (!_no_signal_when_no_waiter) {
+            futex_wait_private(&_pending_signal, expected_state.val, NULL);
+            return;
         }
-        futex_wait_private(&_pending_signal, expected_state.val, nullptr);
-        if (_no_signal_when_no_waiter) {
-            _waiter_num.fetch_sub(1, butil::memory_order_relaxed);
+
+        _waiter_num.fetch_add(1, butil::memory_order_relaxed);
+        // Matching StoreLoad fence for the signal-side fence above. It 
publishes
+        // this waiter before _pending_signal is checked below.
+        butil::atomic_thread_fence(butil::memory_order_seq_cst);
+        // Re-check _pending_signal with a real atomic load, which closes the 
Dekker
+        // pattern at the C++ memory model level(the check inside futex_wait 
is done

Review Comment:
   fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to