apache / apache/brpc

bthread::Mutex在pthread模式下跟butil:mutex(即linux下pthread_mutex_lock)有啥区别

Open
#675 0 comments 0 reactions 0 assignees View on GitHub
discussion
Dominant language
C++
Stars
17.6k
Forks
4.1k
Avg merge
2d 12h
Merged PRs (30d)
69

Description

**Is your feature request related to a problem? (你需要的功能是否与某个问题有关?)**
bthread::Mutex在线程模式会切换到butex_wait->butex_wait_from_pthread->futex_wait_private

那么问题是此时和普通linux的pthread_mutex_lock会有什么差异么?因为看到butil:mutex还是有封装pthread_mutex_lock,如果没差异,按理都无脑使用bthread::Mutex即可,但是不少brpc源码在锁出一些cpu运算没有切bthread的场景,还是选择了butil:mutex(即pthread_mutex_lock)
这种选择是有什么隐含的考虑么?

**Describe the solution you'd like (描述你期望的解决方法)**

**Describe alternatives you've considered (描述你想到的折衷方案)**

**Additional context/screenshots (更多上下文/截图)**

Contributor guide

Open the contributing guide

Research direction

No files, tests, or entry points are named. Start by identifying the brpc implementations of bthread::Mutex and butil::mutex, then compare their pthread-mode behavior and the contexts where each is used. Done means documenting the behavioral difference and the rationale for choosing one in CPU-bound, non-bthread code paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, linux
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.