apache / brpc

brpc is an Industrial-grade RPC framework using C++ Language, which is often used in high performance system such as Search, Storage, Machine learning, Advertisement, Recommendation etc. "brpc" means "better RPC".

Home Page:https://brpc.apache.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bthread 中使用 std::mutex和std::condition_variable导致线程丢失

Cyber-SiKu opened this issue · comments

commented

Describe the bug (描述bug)

当在 bthread 中使用标准库的std::mutex和std::condition_variable时,会导致线程丢失。线程没有退出也没有coredump,导致资源没有回收,引发死锁。

To Reproduce (复现方法)

测试用例
https://github.com/Cyber-SiKu/brpc/pull/1/files

Expected behavior (期望行为)

Versions (各种版本)
OS: centos7 x86_64
Compiler: gcc-11
brpc:
protobuf:

Additional context/screenshots (更多上下文/截图)
在日志中加了一些输出:
image

运行程序可以看到程序死锁,启动了9个线程,并且输出的1.1和1.2并不能成对:
image

gdb 中有8个线程,这与start启动的线程数量不一致。
image

commented

使用bthread相关的锁并不会出现相关的问题。

commented

jump_stack下面是一个使用汇编实现的程序,感觉是里面实现有些问题。

线程锁内挂起协程(协程锁、rpc、bthread_usleep等),会导致死锁。

commented

线程锁内挂起协程(协程锁、rpc、bthread_usleep等),会导致死锁。

看样子像是线程调度出去了,但是再也没有调度回来。

commented

线程锁内挂起协程(协程锁、rpc、bthread_usleep等),会导致死锁。

是不允许这么使用吗?

是的,用协程锁吧。