The synchronization mechanism commonly used to enforce mutual exclusion is semaphore.
- When a process wishes to access a shared resource or crucial section, it must first obtain the semaphore associated with that resource.
- If the semaphore value is not zero (as in the case of a binary semaphore), the process decrements it and continues. This indicates that the resource is currently in use, preventing other programs from using it concurrently.
- If the semaphore value is zero, the process must wait (block) until it is non-zero again, signaling that the resource is ready for usage.