转自
http://blog.csdn.net/typename/article/details/6552191
Linux和windows临界区
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
转自
http://blog.csdn.net/typename/article/details/6552191