7/3/2023 0 Comments Locks monitor and semaphorIn Counting Semaphore, the semaphore S value is initialized to the number of resources present in the system. Semaphore are distinguished by the operating system in two categories Counting semaphores and Binary semaphore. It means that when a process is modifying the value of the semaphore, no other process can simultaneously modify the value of the semaphore. The wait() and signal() operation modify the value of the semaphore indivisibly. Semaphore is typically an integer variable S that is initialized to the number of resources present in the system and the value of semaphore can be modified only by two functions wait() and signal() apart from initialization. Semaphore is a process synchronization tool. If a mutex object is already locked, the process requesting for resources waits and queued by the system till lock is released. If all resources are being used, the process requesting for resource performs wait() operation and block itself till semaphore count become greater than one. Mutex object is locked or unlocked by the process requesting or releasing the resource. Semaphore value is modified using wait() and signal() operation. Semaphore can be categorized into counting semaphore and binary semaphore. Mutex object lock is released only by the process that has acquired the lock on it. Semaphore value can be changed by any process acquiring or releasing the resource. Mutex allow multiple program thread to access a single resource but not simultaneously. Semaphore allow multiple program threads to access a finite instance of resources. There are some more differences between semaphore and mutex, let us discuss them with the help of comparison chart shown below. processes perform wait() and signal() operation to indicate whether they are acquiring or releasing the resource, while Mutex is locking mechanism, the process has to acquire the lock on mutex object if it wants to acquire the resource. A thread can suspend itself in the monitor and wait for an event to occur, in which case another thread is given the chance to enter the monitor.The basic difference between semaphore and mutex is that semaphore is a signalling mechanism i.e. All other threads must wait for the currently executing thread to release the lock. A thread cannot execute any of the routines in the monitor until it acquires the lock, which means that only one thread at a time can execute within the monitor.
0 Comments
Leave a Reply. |