Difference Between Semaphore and Mutex

Mobile Operating SystemMobile DevelopmentOperating System

In this post, we will understand the difference between a semaphore and a mutex −

Semaphore

  • It is used in the signalling mechanism.

  • It is an integer variable.

  • The ‘wait’ and ‘signal’ operations can be used to modify a semaphore.

  • If no resources are available, the process requires that a resource that needs to be executed has to ‘wait’.

  • The process will have to ‘wait’ until the count of the semaphore is higher than 0.

  • Multiple program threads can be used with a semaphore.

  • The value of a semaphore can be changed by any process that releases or obtains the resource.

  • There are different kinds of semaphores: Counting semaphore and Binary semaphore.

  • The value of a semaphore can be changed using ‘wait’ operation and ‘signal’ operation.

  • The process is occupied if all resources are used.

  • The process requesting the resource uses the ‘wait’ operation and blocks itself until the count of the semaphore becomes greater than 1.

Mutex

  • It is used in locking mechanism.

  • It is an object.

  • It is modified by that process (only) that requests or releases a resource.

  • If the mutex is locked, then the process will have to wait.

  • The process is kept in a queue when mutex s locked.

  • This can be accessed only after the mutex has been unlocked.

  • Multiple program threads can be used in mutex (but not simultaneously).

  • The lock on the object can be released by the process only, which would have obtained the lock on it.

  • It doesn’t have any subtypes.

  • The object is either locked or unlocked.

  • If the object has already been locked, the process that requests the resources will wait.

  • It will be queued by the system before the lock has been released.

raja
Published on 20-Apr-2021 08:59:48
Advertisements