mutex_lock(9)
π mutex_lock(9) β Kernel API Manual
Okay so bestie, welcome to the mutex_lock(9) page, we're doing kernel locking today and honestly? It's giving main character energy. Sit down, hydrate, let's go. π«Ά
β¨ NAME β¨
mutex_lock β acquire the mutex π
πΈ SYNOPSIS πΈ
void mutex_lock (struct mutex *lock );
π ARGUMENTS π
lockβ the mutex you're about to acquire, i.e. the whole reason we're here π
π¦ DESCRIPTION π¦
So here's the vibe: you call this and it locks the mutex exclusively for this task. Just you. Nobody else. If the mutex isn't available right now? It does not panic, it does not spin, it just sleeps until it can get it. Very demure. Very mindful. π΄
Now the rules, and bestie, these are not optional:
- The mutex must later on be released by the same task that acquired it. Like, the exact same one. No sending your friend to unlock it for you.
- Recursive locking is not allowed β do not try to lock the thing you already locked, it will not go well for you, fr fr.
- The task may not exit without first unlocking the mutex.
- Also, kernel memory where the mutex resides must not be freed with the mutex still locked π.
- The mutex must first be initialized (or statically defined) before it can be locked. Non-negotiable.
- And ngl,
memset-ing the mutex to 0 is not allowed. Do not do it. I'm serious. π
Okay so there's actually help for all of this: theCONFIG_DEBUG_MUTEXES.configoption turns on debugging checks that will enforce the restrictions, and it'll also do deadlock debugging for you. Iconic of it, honestly. π
Also, for the record: this function is similar to (but not equivalent to) down.
π SEE ALSO π
Kernel file ./kernel/locking/mutex.c, plus all these besties:
mutex_unlock(9)ww_mutex_unlock(9)ww_mutex_trylock(9)mutex_lock_interruptible(9)mutex_lock_killable(9)mutex_lock_io(9)mutex_trylock(9)atomic_dec_and_mutex_lock(9)
That's the whole page, bestie β go lock something responsibly (and unlock it with the same task, please π). This one lives in ./kernel/locking, and it's dated October 2026, so it's basically brand new. Slay, bye! π
β¨π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms