首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

自旋锁跟mutex有什么区别

2012-08-29 
自旋锁和mutex有什么区别平台:windows环境:mfc有一个类叫CMutex,很方便用,可是总是会和CSingleLock放在一

自旋锁和mutex有什么区别
平台:windows

环境:mfc

有一个类叫CMutex,很方便用,可是总是会和CSingleLock放在一块。。

利用c++ 析构函数的特征,西沟的时候释放锁。

如:

CMutex rwMutex; 
CSingle sLock(&rwMutex); 
  sLock.Lock(); 
  .... 
  sLock.UnLock();

有人把这个叫做自旋锁。 请问 自旋锁到底是什么???


问题2: 也可以自己实现一个CMyMutex,析构函数里实现unlock

根本不必依赖CSingleLock3类。

不知道我理解的对不对???



[解决办法]
《Windows核心编程》

mk:@MSITStore:D:\MSDN98\98VS\2052\winbase.chm::/devdoc/live/pdwbase/synchro_6fn2.htm
About Synchronization
To synchronize access to a resource, use one of the synchronization objects in one of the wait functions. The state of a synchronization object is either signaled or nonsignaled. The wait functions allow a thread to block its own execution until a specified nonsignaled object is set to the signaled state.

The following are other synchronization mechanisms: 

overlapped input and output 
asynchronous procedure calls 
critical section objects 
interlocked variable access 
 

热点排行