Skip to content

Instantly share code, notes, and snippets.

@ajaynitt
Created October 11, 2014 17:19
Show Gist options
  • Save ajaynitt/e3fbc1cea0a63563d0fe to your computer and use it in GitHub Desktop.
Save ajaynitt/e3fbc1cea0a63563d0fe to your computer and use it in GitHub Desktop.
Mutex Semaphore
Mutex:
a mutex is locking mechanism used to synchronize access to a resource. Only one task (can be a thread or process based on OS abstraction) can acquire the mutex. It means there will be ownership associated with mutex, and only the owner can release the lock (mutex).
Is a key to a toilet. One person can have the key - occupy the toilet - at the time. When finished, the person gives (frees) the key to the next person in the queue
Semaphore:
Semaphores are typically used as a signaling mechanism between processes.
A typical example is a producer-consumer process pair (not explained here to keep the answer to a readable length).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment