and*_*and 1 c posix mutex pthreads
假设我锁定了一个名为的互斥锁 wfg
pthread_mutex_lock(&wfg);
//and then I return from the function
return 0;
Run Code Online (Sandbox Code Playgroud)
互斥锁会保持锁定状态吗?
互斥锁保持锁定状态,直到pthread_mutex_unlock从获得锁定的线程调用它为止.功能与它无关.你可以有类似的东西
pthread_mutex_t wfg;
...
void razzle()
{
pthread_mutex_lock(&wfg);
}
void dazzle()
{
pthread_mutex_unlock(&wfg);
}
...
razzle();
... do stuff ...
dazzle();
Run Code Online (Sandbox Code Playgroud)
那会很好(但很傻).