Skip to content

【咨询】bthread 互斥锁为什么不像 pthread 互斥锁一样实现递归锁(可重入锁)? #3194

@fox-half-tian

Description

@fox-half-tian

我需要将原本运行在 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 级别的递归锁,有这样的实现案例吗?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions