IT Community - Software Programming, Web Development and Technical Support

What is the difference between Mutex and Binary semaphore?

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?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-15-2007, 07:32 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default What is the difference between Mutex and Binary semaphore?

What is the difference between Mutex and Binary semaphore?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-16-2007, 12:33 AM
Senthilkumar Senthilkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 93
Senthilkumar is on a distinguished road
Default Re: What is the difference between Mutex and Binary semaphore?

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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 05:55 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0