ehds commented on PR #2156: URL: https://github.com/apache/brpc/pull/2156#issuecomment-1923713768
> > > 加上这个patch后,稳定出现第一种错误,是 socket.cpp 也有类似的问题吗? > > > > > > 是在哪个平台上出现呢?arm 还是 x86 ? 可以贴下 PoC 代码。 > > x86, `(defined(__aarch64__) || defined(__arm64__))`,去掉后不再core在前面提到的两个位置。 > > core在了其他地方,找了下调用栈,有地方是这么用的 `static thread_local Object obj;`。是用了btread的地方,只要用到 thread_local 的都需要做类似的变更吗? > > 我之前没用过brpc,如何能够构造一个,问题里提到到示例呢? 如果使用 thread_local 变量时,前后两次该变量的中间阶段发生了 bthread 的切换(由于 `start_urgent` 或者 `butex` 等待,`bthread_usleep` 等操作),那么 `thread_local` 变量就可能不是之前的对象了,这个和 bthread 的设计相关,因为 bthread 运行周期可以被调度到不同的 pthread 上执行,所以前后两次所在的 pthread 上下文已经变化,其 thread_local 变量也就变化了。 具体见:https://brpc.apache.org/docs/bthread/thread-local/#thread-local%E9%97%AE%E9%A2%98 > 是用了btread的地方,只要用到 thread_local 的都需要做类似的变更吗? 这个得分情况:如果想要在 bthread 中使用类似 "thread_local" 的行为,即无论 bthread 被调度到哪,都获得相同的 thread_local 值,建议使用 `bthread_local` https://brpc.apache.org/zh/docs/server/basics/#bthread-local 如果代码就是想要获得当前被调度运行的 pthread 线程的 `thread_local` 变量(例如 brpc 中的 `tls_task_group `),那么就建议如果会出现上述导致 bthread 切换的行为,那么建议使用这个宏,避免编译器的优化。 -- 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