(转)使用互斥锁

 

一、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_init(&mylock, NULL);
 
2、销毁
pthread_mutex_destroy(&mylock);
 
3、操作
pthread_mutex_lock(&mylock);
pthread_mutex_unlock(&mylock);

 

posted @ 2010-09-06 15:52  木子你妹  阅读(2440)  评论(0编辑  收藏  举报