【咨询】bthread 互斥锁为什么不像 pthread 互斥锁一样实现递归锁(可重入锁)?
- Dominant language
- C++
- Stars
- 17.6k
- Forks
- 4.1k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 69
Description
我需要将原本运行在 pthread 上的业务切换到 bthread 上,但有的业务中 pthread 互斥锁设置了属性 PTHREAD_MUTEX_RECURSIVE_NP,这导致无法直接实现 bthread 切换。
我看了 bthread_mutex_init 源码实现,虽然有 attr 参数,但是看上去是为了兼容 pthread_mutex_init,其实忽略了 attr 参数。
为什么不做实现呢?这与官方文档 Goals 章节所述“bthread所有接口可在pthread中被调用并有合理的行为,使用bthread的代码可以在pthread中正常执行。”并不完全准确。
如果需要兼容,看上去我需要参考 pthread,基于 bthread 封装一个实现,添加 owner id 和ref_ count 来实现 bthread 级别的递归锁,有这样的实现案例吗?
Contributor guide
Research direction
Start by reading the bthread_mutex_init implementation and the Goals section of the documentation, then compare its attr handling with pthread mutex behavior. Determine whether recursive locking is intended to be supported and whether existing bthread-level implementations or examples are referenced. Done means the compatibility question has a documented resolution or a clearly scoped implementation plan.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100