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

   ### What problem does this PR solve?
   
   Issue Number: resolve #3274
   
   Problem Summary:
   
   The join/end handshake on `version_butex` was not correctly synchronized.
     - Producer (`task_runner`, at bthread end): bumped the version with a 
plain write 
       `++*m->version_butex`. The surrounding `version_lock` provides release 
semantics 
       only to threads that also take that lock, but `join()` does not, so 
there is no release on 
       `version_butex` for the join path.
     - Consumer (`TaskGroup::join`): exited its wait loop via a plain read 
`*m->version_butex`, 
        with no acquire ordering.
   
   The result is a data race with no happens-before edge, so writes the joined 
bthread made 
   before ending were not guaranteed visible after `join()` returned. On x86 
(TSO) the hardware 
   masked this, but on ARM it surfaced.
   
   PR #3276 attempted a fix by adding a lone `atomic_thread_fence(acquire)` 
after the loop. But 
   per the C++ memory model an acquire fence only establishes synchronization 
when a preceding 
   atomic load reads a value from a matching release operation. Here the load 
was a plain read and 
   the producer had no release store, so the fence pairs with nothing. It 
happens to work on ARM 
   only because the compiler emits a real `dmb ishld`, not because the model 
guarantees it. 
   
   ### What is changed and the side effects?
   
   Changed:
   
   This PR replaces that band-aid with a properly paired release/acquire on 
`version_butex`.
   
   Side effects:
   - Performance effects:
   
   - Breaking backward compatibility: 
   
   ---
   ### 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