假设我锁定了一个名为互斥wfg
如果我在不调用pthread_mutex_unlock的情况下从函数返回会怎么样?
pthread_mutex_lock(&wfg);
//and then I return from the function
return 0;
会互斥保持锁定?
假设我锁定了一个名为互斥wfg
如果我在不调用pthread_mutex_unlock的情况下从函数返回会怎么样?
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();
而且这将是罚款(但愚蠢)。