双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

关于 linux 下 pthread_cond_wait 的原子操作疑问??

hzhxxx hzhxxx 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
关于 linux 下 pthread_cond_wait 的原子操作疑问??
int pthread_cond_timedwait(pthread_cond_t *restrict cond,
pthread_mutex_t *restrict mutex,
const struct timespec *restrict abstime);

int pthread_cond_wait(pthread_cond_t *restrict cond,
pthread_mutex_t *restrict mutex);

1. pthread_cond_wait 这个函数的主要功能是等待条件变量cond,其实现逻辑是
先把调用线程加入到等待条件变量的列表,然后把解锁mutex,最后阻塞(suspending)调用线程;
2. 当有线程调用 pthread_cond_broadcast(signal) 发送信号后,pthread_cond_wait
解锁再次锁定 mutex,返回给调用线程;

为什么第一步过程中
Unlocking the mutex and suspending on the condition variable is done atomically.
解锁和阻塞要是原子操作???
...全文
评论 7
收藏 已收藏
分享
返回顶部
hzhxxx
C++ 语言 65,214 成员 250,514 内容