gpt4 book ai didi

c - 如果我从一个函数返回而不调用 pthread_mutex_unlock 会发生什么?

转载 作者:太空宇宙 更新时间:2023-11-04 00:15:45 25 4
gpt4 key购买 nike

假设我锁定了一个名为 wfg

的互斥锁
pthread_mutex_lock(&wfg);
//and then I return from the function
return 0;

互斥体会保持锁定状态吗?

最佳答案

互斥锁保持锁定状态,直到从获得锁的线程调用 pthread_mutex_unlock。功能与它无关。你可以有类似的东西

pthread_mutex_t wfg;
...
void razzle()
{
pthread_mutex_lock(&wfg);
}

void dazzle()
{
pthread_mutex_unlock(&wfg);
}

...
razzle();
... do stuff ...
dazzle();

那会很好(但很愚蠢)。

关于c - 如果我从一个函数返回而不调用 pthread_mutex_unlock 会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4774332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com