- 论坛徽章:
- 0
|
对信号量,我一直这样认为的,而且初始值为S,当一进程申请资源时,执行wait()操作,mutex--,S值减1;当操作结束后执行signal() 操作,mute++,S值加1。
对于互斥信号量,这就意味着1是unlocked,0是locked
近日看到另外一个说法:
A mutex is a variable that can be in one of two states: unlocked or locked. Consequently, only 1 bit is required to represent it, but in practice an integer often is used, with 0 meaning unlocked and all other values meaning locked. Two procedures are used with mutexes. When a process (or thread) needs access to a critical region, it calls mutex_lock. If the mutex is currently unlocked (meaning that the critical region is available), the call succeeds and the calling thread is free to enter the critical region.
而这就意味着0是unlocked,1是locked
是不是这两者说的不是一个事,我按上面两种方法来实现互斥功能,都成功了,我都糊涂了。
[ 本帖最后由 rock_jq 于 2008-8-7 17:26 编辑 ] |
|