使用 bthread 出现异常情况
- Dominant language
- C++
- Stars
- 17.6k
- Forks
- 4.1k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 69
Description
**Describe the bug (描述bug)**
```c++
class B1 {
public:
virtual ~B1() {}
};
class B2 {
public:
virtual ~B2() {}
static void* RunThis(void *arg) {
static_cast(arg)->Run();
return nullptr;
}
void Run() {
// inotifywait_child 是一个 boost::process::child, 监视文件变更, 然后上报
while (inotifywait_child->running() && std::getline(*_out, file)) {
try {
foo();
} catch (...) {
}
}
}
virtual void foo() {}
void bar() {
bthread_t tid;
bthread_start_background(&tid, nullptr, RunThis, this);
// 改用 BTHREAD_ATTR_PTHREAD 后, 未复现
// bthread_start_background(&tid, &BTHREAD_ATTR_PTHREAD, RunThis, this);
}
};
class D1 : public B1, public B2 {
public:
void foo() override;
}
```
在 ``B2::bar()`` 中使用默认参数 ``bthread_start_background`` 执行了类似上面代码的任务, 结果崩溃在 ``D1::foo`` 部分, 此时显示 ``this=0x0``.
改用 `pthread_create` 或添加 `BTHREAD_ATTR_PTHREAD` 属性后正常, 这个是使用方式不对还是有什么可能的问题?
**To Reproduce (复现方法)**
暂无最小复现例子.
**Expected behavior (期望行为)**
使用默认参数
**Versions (各种版本)**
OS: RHEL/CentOS 8
Compiler: 8.3.1
brpc: 7bda11bc312d422b3e293b19b8b82a711da26c94
protobuf: 3.5.0
**Additional context/screenshots (更多上下文/截图)**
Contributor guide
Research direction
Start at B2::bar(), B2::RunThis(), and the bthread_start_background call, comparing the default attributes with BTHREAD_ATTR_PTHREAD and pthread_create. First reduce the inheritance and boost::process interaction to a minimal reproduction; done means identifying whether the default bthread usage or another lifetime issue explains the crash in D1::foo with this=0x0.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100