mutex 和 semaphone 的区别 (1)
2010-09-04 12:13
423 查看
MSDN:
A thread that owns a mutex object can wait repeatedly for the same mutex object
to become signaled without its execution becoming blocked. A thread that waits
repeatedly for the same semaphore object, however, decrements the semaphore's
count each time a wait operation is completed; the thread is blocked when the
count gets to zero. Similarly, only the thread that owns a mutex can
successfully call the ReleaseMutex
function, though any thread can use ReleaseSemaphore to increase the count of
a semaphore object.
本以为数量为1的semaphone和mutex没有区别,读了上面这段说明才知道,mutex的owner线程可以无限次成功调用ReleaseMutex,而ReleaseSemaphore则不判断调用是否来自owner线程。感觉上这种设计让semaphore更符合计数器的这样一个语义。
A thread that owns a mutex object can wait repeatedly for the same mutex object
to become signaled without its execution becoming blocked. A thread that waits
repeatedly for the same semaphore object, however, decrements the semaphore's
count each time a wait operation is completed; the thread is blocked when the
count gets to zero. Similarly, only the thread that owns a mutex can
successfully call the ReleaseMutex
function, though any thread can use ReleaseSemaphore to increase the count of
a semaphore object.
本以为数量为1的semaphone和mutex没有区别,读了上面这段说明才知道,mutex的owner线程可以无限次成功调用ReleaseMutex,而ReleaseSemaphore则不判断调用是否来自owner线程。感觉上这种设计让semaphore更符合计数器的这样一个语义。
相关文章推荐
- spin_lock & mutex_lock的区别? .
- 各种Mutex的使用与区别
- C++ 多线程资源锁的两种表现形式--Mutex和Critical Section的区别
- 互斥锁Mutex与信号量Semaphore的区别
- spin_lock & mutex_lock的区别? 【转】
- 临界区(Critical section)与互斥体(Mutex)的区别
- Critical Section,Mutex,Semaphore,Event区别
- Spin lock 与mutex 的区别
- 内核中DEFINE_MUTEX DECLARE_MUTEX DEFINE_SEMAPHORE的区别
- 事件(event)与互斥量(mutex)区别
- spin_lock & mutex_lock的区别? .
- std::unique_lock<std::mutex> or std::lock_guard<std::mutex> C++11 区别
- 临界区(Critical section)与互斥体(Mutex)的区别
- 各种Mutex(互斥量)的区别
- 【转】自旋锁spin和互斥量mutex的区别
- spin_lock & mutex_lock的区别
- lock,Monitor,Mutex的区别
- 温习小知识--mutex和spin lock的区别和应用
- mutex和semaphore的区别
- Event和Mutex区别