songgaoye opened a new pull request, #3774:
URL: https://github.com/apache/brpc/pull/3774

   ### What problem does this PR solve?
   
   Issue Number: resolve
   
   Problem Summary:
   
   `TimerThread::Bucket::consume_tasks()` read `_task_head` without holding
   `Bucket::_mutex`, while concurrent `schedule()` calls update the same 
linked-list
   head under the mutex. This is a C++ data race.
   
   Simply locking every call to `consume_tasks()` fixes the race but regresses 
the
   sparse-bucket fast path: the timer thread scans every bucket, most of which 
are
   typically empty.
   
   ### What is changed and the side effects?
   
   Changed:
   
   - Add an atomic `_has_tasks` hint to each `TimerThread::Bucket`.
   - Publish the hint after linking a task while holding the bucket mutex.
   - Skip locking empty buckets based on the atomic hint.
   - Keep all accesses to `_task_head` protected by `Bucket::_mutex`.
   - Add tests for sparse buckets, later tasks that do not issue an additional
     wakeup, and concurrent scheduling into one bucket.
   
   Side effects:
   
   - Performance effects:
   
     Restores the empty-bucket fast path without reading `_task_head` outside 
its
     mutex. In a sparse 1024-bucket benchmark, the mutex-only variant took about
     146–147 ms, while the atomic-hint version took about 22–24 ms.
   
   - Breaking backward compatibility:
   
     None.
   
   ---
   
   ### Check List:
   
   - Please make sure your changes are compilable.
   - When providing us with a new feature, it is best to add related tests.
   - Please follow [Contributor Covenant Code of 
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).


-- 
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