This is a discussion on What is the difference between Mutex and Binary semaphore? within the C and C++ Programming forums, part of the Software Development category; What is the difference between Mutex and Binary semaphore?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| First, "semaphore" is a fairly generic term. In common practice, there are 3 separate sets of UNIX-heritage interfaces for "semaphores". Two (System V and POSIX) are "counting" semaphores, which have "values", and the other (BSD) is a "binary" semaphore, which is either locked or not locked. A mutex is essentially a binary semaphore, but with the additional property that it is logically "owned" by the executable entity (whether process or thread) that locked it. This property improves code structuring and allows some useful optimizations. You can't lock a mutex in one thread and then unlock it in another. You CAN, however, lock a binary semaphore in one thread and unlock it in another, because while a binary semaphore may be "locked" or "unlocked", it is never "owned". A counting semaphore can be used to manage multiple resources, or for generalized blocking rather than "locking". That is, a semaphore initialized to the value 0 will always block when {waited, locked, decreased}, and the waiter will be unblocked when it is {increased, posted, unlocked}. If you initialize the semaphore to 1, the first "lock" will succeed, while a second will block. If you have 5 shared buffers, you can sometimes manage them simply by using a counting semaphore initialized to the value 5. (The first 5 "locks" succeed, and subsequent "locks" block until the semaphore is "unlocked".) Senthil Kumar Last edited by Senthilkumar : 07-16-2007 at 12:49 AM. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What is Binary Portability Testing? | simplesabita | Software Testing | 1 | 11-13-2007 04:36 AM |
| Development using Binary? | prasannavigneshr | Technology BUZZzzzzz | 12 | 08-06-2007 10:11 AM |
| How to convert Decimal to Binary in Flash? | kingmaker | Flash Actionscript Programming | 1 | 07-21-2007 02:48 AM |
| How can i convert integers to binary or hexadecimal? | prasath | C and C++ Programming | 1 | 07-20-2007 07:31 AM |
| Application Binary Interface(ABI) | simplesabita | Software Testing | 1 | 07-19-2007 07:05 AM |