Mutexes in the Linux kernel

Mutex means mutual Exclusion. The mutex provides a mechanism to protect critical data. The mutex allows a process/thread to go to sleep state in case the lock cannot be acquired immediately. This is in contrast to a spinlock wherein the calling process/thread keeps spinning at obtaining the lock and does not go down to sleep. […]

Mutex API

The Mutex API can be defined statically using the “DEFINE_MUTEX” MACRO. It can be dynamically defined during process/thread run using the “mutex_init” MACRO. Both methods are shown below DEFINE_MUTEX(mutex_name); /*statically assign mutex by name- mutex_name*/ mutex_init(mutex); /* dynamically assign the mutex */ Both these Macros are placed in the header file – mutex.h. The code […]