Crate ticketed_lock

Source
Expand description

Ticketed lock.

Ticketed lock is similar to RwLock, except that the acquisition of the lock is split:

  1. obtaining a ticket, which has to be done on the same thread as the locked storage
  2. waiting on a ticket, which puts the current thread to sleep until the ticket is due. That moment comes when all the previous tickets are processed.
  3. working with the data behind a read/lock guard
  4. when the guard is freed, it allows the following tickets to become active

A ticket can be moved between threads or even just lost. Consecutive read-only tickets do not guarantee a particular lock order. All the ticket counting is done based on Arc primitives, and the only unsafe code that this library has is for accessing the actual data behind a guard.

Structsยง

ReadLockGuard
The read-only guard of data, allowing &T dereferences.
ReadTicket
A ticket to read the data at some point.
TicketedLock
The ticketed lock, which wraps the data.
WriteLockGuard
The read/write guard of data, allowing &mut T dereferences.
WriteTicket
A ticket to read/write the data at some point.