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.进入和退出临界区
#ifdef _LINUX
thread_mutex_lock(&mutex_lock);
......
pthread_mutex_unlock(&mutex_lock);
#endif
#ifdef _WIN32
EnterCriticalSection(&mutex_lock);
....
LeaveCriticalSection(&mutex_lock);
#endif
4.删除临界区
#ifdef _LINUX
pthread_mutex_destroy(&mutex_lock);
#endif
#ifdef WIN32
DeleteCriticalSection(&mutex_lock);
#endif
版权声明:本文为博主原创文章,未经博主允许不得转载。
本文摘自 :https://blog.51cto.com/l