wwbmmm commented on code in PR #2147:
URL: https://github.com/apache/brpc/pull/2147#discussion_r1127642318
##########
src/bthread/work_stealing_queue.h:
##########
@@ -115,15 +119,22 @@ class WorkStealingQueue {
// Returns true on stolen.
// May run in parallel with push() pop() or another steal().
bool steal(T* val) {
- size_t t = _top.load(butil::memory_order_acquire);
+ // no instructions before _top.store() must be aware
+ size_t t = _top.load(butil::memory_order_relaxed);
+
size_t b = _bottom.load(butil::memory_order_acquire);
if (t >= b) {
// Permit false negative for performance considerations.
return false;
}
do {
- butil::atomic_thread_fence(butil::memory_order_seq_cst);
+ // erased: butil::atomic_thread_fence(butil::memory_order_seq_cst);
+ // no instruction before _top.cas must be known to other pthreads
b = _bottom.load(butil::memory_order_acquire);
+
+ // If not get t again and another steal() happens
+ // after the first getting, it might stuck in a dead circle
+ t = _top.load(butil::memory_order_acquire);
Review Comment:
if compare_exchange_strong returns false, the current value of _top will be
stored in t. No need to load again here.
--
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]