r****o 发帖数: 1950 | 1 一直觉得很奇怪,semaphore不是进程间的同步机制吗?
为啥老见人说semaphore是进程间的通信机制呢? 光靠semaphore能实现连个进程间的通
信吗? | l*******y 发帖数: 1498 | 2 mutex是专门用来同步的, semaphonre既可以用来同步也可以用来通信。因为mutex只
能由拥有mutex的那个进程释放,而semaphonre可以由非拥有的进程释放。这也是mutex
和 binary semaphonre的一个主要区别吧。
Consider I/O examples, we pick up a binary semaphore to wait for some kind
of I/O, when the I/O comes, task picks up the byte, the task then releases
the same semaphore. This cannot be done with a mutex. | c****a 发帖数: 11 | 3 你的i/o example里面 为什么不能用mutex?
mutex
【在 l*******y 的大作中提到】 : mutex是专门用来同步的, semaphonre既可以用来同步也可以用来通信。因为mutex只 : 能由拥有mutex的那个进程释放,而semaphonre可以由非拥有的进程释放。这也是mutex : 和 binary semaphonre的一个主要区别吧。 : Consider I/O examples, we pick up a binary semaphore to wait for some kind : of I/O, when the I/O comes, task picks up the byte, the task then releases : the same semaphore. This cannot be done with a mutex.
| l*******y 发帖数: 1498 | 4 thread1 waits for the I/O to complete, thread2 is responsible for completing
the I/O operation. thread1 get the semaphonre first, thread2 realse it then
. Then thread1 find the I/O operation completes and can do the following
things. This is a kind of communication.
If use mutex, if thread1 get the mutex, only thread1 can release the mutex.
【在 c****a 的大作中提到】 : 你的i/o example里面 为什么不能用mutex? : : mutex
|
|