Module priomutex::spin_one
[−]
[src]
A high-performance variant of priomutex.
This mutex is very similar to the one in the root of the crate, except that the next-in-line thread
busy-waits. This means that dropping the MutexGuard
never requires any syscalls, and takes
100-200ns on my machine (20x faster than the standard priomutex). No matter how many threads are
waiting on your mutex, it's guaranteed that only one will be busy-waiting at any time.
Suppose thread 1 has the lock and thread 2 is busy-waiting for it. Now thread 3 tries to lock the
mutex with a higher priority then thread 2. Thread 3 will now busy-wait, while thread 2 goes to
sleep. When thread 1 releases the lock, thread 3's lock
call will return, while thread 2 wakes
up and starts busy-waiting once more.
Structs
Mutex |
A mutex which allows waiting threads to specify a priority. |
MutexGuard |
An RAII guard. Frees the mutex when dropped. |