1.聲明
?
#ifdef _LINUX
pthread_mutex_t ? mutex_lock;
#endif
#ifdef WIN32
CRITICAL_SECTION ?mutex_lock;
#endif
2.初始化
?
#ifdef _LINUX
pthread_mutex_init(&mutex_lock, NULL);
#endif
#ifdef WIN32
InitializeCriticalSection(&mutex_lock);
#endif
3.進入和退出臨界區(qū)
?
#ifdef _LINUX
thread_mutex_lock(&mutex_lock);
......
pthread_mutex_unlock(&mutex_lock);
#endif
?
#ifdef _WIN32
EnterCriticalSection(&mutex_lock);
....
LeaveCriticalSection(&mutex_lock);
#endif
4.刪除臨界區(qū)
#ifdef _LINUX
pthread_mutex_destroy(&mutex_lock);
#endif
#ifdef WIN32
DeleteCriticalSection(&mutex_lock);
#endif
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。
本文摘自 :https://blog.51cto.com/l