res*_*way 2 c++ linux inline atomicity
如果有两个线程调用此问题,那么我可以解决以下代码中解锁后的linux上下文切换问题
inline bool CMyAutoLock::Lock(
pthread_mutex_t *pLock,
bool bBlockOk
)
throw ()
{
Unlock();
if (pLock == NULL)
return (false);
// **** can context switch happen here ? ****///
return ((((bBlockOk)? pthread_mutex_lock(pLock) :
pthread_mutex_trylock(pLock)) == 0)? (m_pLock = pLock, true) : false);
}
Run Code Online (Sandbox Code Playgroud)