- 论坛徽章:
- 0
|
本帖最后由 digdeep126 于 2011-11-25 13:53 编辑
回复 54# 埋头苦编
你的翻译,我实在看不明白,还是看原文吧:
http://publib.boulder.ibm.com/in ... progc%2Fmutexes.htm
The thread that locked a mutex is often called the owner of the mutex.
The pthread_mutex_unlock subroutine resets the specified mutex to the unlocked state if it is owned by the calling mutex under the following conditions:
If the mutex was already unlocked, the subroutine returns an error.
If the mutex was owned by the calling thread, the subroutine unlocks the mutex.
If the mutex was owned by another thread, the subroutine might return an error or unlock the mutex depending on the type of mutex. Unlocking the mutex is not recommended because mutexes are usually locked and unlocked by the same pthread.
既然:Unlocking the mutex is not recommended
那么推荐的方式就是: 对pthread_mutex_unlock函数的调用,不应该解锁“非自己线程拥有的锁”。
那我们在往前推一步:既然pthread_mutex_unlock函数不应该解锁“非自己线程拥有的锁”,那么“自己线程拥有的锁”就只能是拥有锁的线程自己调用pthread_mutex_unock来解锁了,也就是说“推荐的方式是:谁加锁,谁解锁。”
另:“The pthread_mutex_unlock subroutine resets the specified mutex to the unlocked state if it is owned by the calling mutex under the following conditions:”这一句英文中的:calling mutex似乎应该为 calling thread (仅仅是自己的猜测!) |
|