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

   ### What problem does this PR solve?
   
   Issue Number: resolve
   
   Problem Summary:
   
   `Server::StartInternal()` creates temporary bthreads to run
   `ServerOptions::bthread_init_fn`.
   
   The initialization bthread writes `BthreadInitArgs::done` and repeatedly 
reads
   `BthreadInitArgs::stop`, while the startup thread reads `done` and writes
   `stop`. These fields were ordinary `bool`s, so the concurrent accesses formed
   C++ data races. In particular, observing completion did not safely publish 
the
   init callback result, and the init bthread was not synchronized with the
   shutdown request.
   
   ### What is changed and the side effects?
   
   Changed:
   
   - Make `BthreadInitArgs::done` and `stop` atomic.
   - Publish init completion with a release store after writing `result`.
   - Consume completion with an acquire load before proceeding with startup.
   - Synchronize the stop request with release/acquire operations.
   - Add a barrier-based regression test covering the init callback completion,
     startup, stop, and join handoff.
   
   The new test reports the original race under TSAN on the unmodified code. The
   targeted `BthreadInitEntry` / `StartInternal` report disappears after this
   change.
   
   Side effects:
   
   - Performance effects:
   
     This affects only temporary server-startup bthreads. It adds atomic 
accesses
     to their completion and stop polling paths, not RPC request processing.
   
   - 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