mutex_lock() / mutex_unlock()¶
Purpose¶
Protects shared state in process context where sleeping is allowed.
Header¶
Prototype¶
Parameters¶
lock: pointer to an initializedstruct mutex.
Return Value¶
mutex_lock()returns no value and may sleep.mutex_unlock()releases the mutex.
Minimal Example¶
Common Pitfalls¶
- Do not use mutexes in hard IRQ context.
- Avoid holding mutexes while copying large data to/from user space.
- Use clear ownership rules to prevent deadlocks.