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

   ### What problem does this PR solve?
   
   Issue Number:https://github.com/apache/brpc/issues/1776, 
https://github.com/apache/brpc/issues/1407, 
https://github.com/apache/brpc/issues/845,https://github.com/apache/brpc/issues/1860,
 https://github.com/apache/doris/pull/13270
   
   Problem Summary:
   编译器会优化 thread_local 的变量的读写,如果在函数过程中间,线程发生切换(bthread 切换到另一个线程执行),那么 
thread_local 变量需要重新获当前运行线程的,而不应该使用之前的旧值。
   
   经测试,Apple M1 Apple clang version 14.0.0, 编译依然存在该问题。
   gcc 通过开启 fno-gcse 选项禁止该优化,clang 未能找到对应控制选项。
   
   ### What is changed and the side effects?
   
   Changed:
   1. 新增 `NOT_ALLOW_OPTIMIZE_THREAD_LOCAL_ACCESS` 用于控制是否允许编译器优化,如果为 true 
是,对应的thread local 变量必须通过 noinline 的函数调用方式来获取最新值,绕开编译器的优化。
   Side effects:
   - Performance effects(性能影响):
   如果开启 `NOT_ALLOW_OPTIMIZE_THREAD_LOCAL_ACCESS` , 会造成多一次的函数调用开销。
   - 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](../../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: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to