读书人

自旋锁跟mutex有什么区别

发布时间: 2012-08-29 08:40:14 作者: rapoo

自旋锁和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

读书人网 >C语言

热点推荐