# Mutex --- ## Object Definitions ```c typedef struct { kpl_task_queue queue; _Atomic int32_t lock; } kpl_mutex; ``` ## Usage 1. Before adding to the `queue` do `value = lock++` 2. Add to the queue 3. If `value` is `0` the thread does an async schedule of the mutex task, otherwise the thread moves on ### Mutex Task 1. Get task from `queue` and run task * Use spinlock with `pasue`, the `lock` will be set before the task is added to the `queue` 2. After task completion, do `value = --lock`, stop if `value` is `0`, otherwise repeat