(转)使用互斥锁
一、Windows环境:
1、API
CRITICAL_SECTION mylock;
InitializeCriticalSection(&mylock);
EnterCriticalSection(&mylock);
LeaveCriticalSection(&mylock);
2、MFC
CCriticalSection mylock;
mylock.Lock();
mylock.Unlock();
二、Unix环境:
1、创建
pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; 或者
pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER; 或者
pthread_mutex_t mylock;
pthread_mutex_init(&mylock, NULL);
pthread_mutex_init(&mylock, NULL);
2、销毁
pthread_mutex_destroy(&mylock);
pthread_mutex_destroy(&mylock);
3、操作
pthread_mutex_lock(&mylock);
pthread_mutex_unlock(&mylock);
pthread_mutex_unlock(&mylock);