Semaphores in the Linux Kernel

Another synchronization mechanism that is provided in the Linux kernel is the Semaphore. It provides the ability for multiple kernel processes/threads to access a resource simultaneously using a “count” value. If the “count” value is 1, then the semaphore is similar to a mutual exclusion lock (Mutex). However, a Semaphore does not have the same ownership rules that a Mutex supports.

Some of the characteristics of the Semaphore is provided below

1 Semaphore locks can sleep
2 Semaphore locks have a count value which allows greater than one instance of the lock to be acquired
3 Semaphores are not usually used in ISRs or time critical flows as the semaphore lock can go to sleep
4 Semaphore which has a “count” value of 1 is termed a binary Semaphore.
5 The “count” value during initialization depicts how many instances of the semaphore can be obtained

In the next couple of articles, we will look at the semaphore structure, different semaphore APIs and also look at a simple usage example of a semaphore.

Semaphore Structures and Semaphore APIs in Linux KErnel

Comments

  1. Pingback: Mutex API List and Sample API Code | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *