Skip to content

A small, fair, reader-writer ticket-based spinlock which allows many readers to acquire the lock at the same time while allowing only one writer at at time while preventing starvation of writers and readers.

License

Notifications You must be signed in to change notification settings

goodcleanfun/rw_ticket_spinlock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rw_ticket_spinlock

A small (50x smaller than pthread_rwlock_t), fair, reader-writer ticket-based spinlock which allows many readers to acquire the lock at the same time while allowing only one writer at at time and serves requests in FIFO order to prevent starvation of writers and readers. See the rwticket lock in https://locklessinc.com/articles/locks/ for more details. This implementation has similar functionality just using C11 atomics on separate fields. The WiredTiger implementation fixes some of the subtle bugs in the union implementation, and need to benchmark the two approaches but in theory this implementation incurs one more atomic operation during writer unlock (not a big deal when reads are more prevalent) but can use slightly cheaper atomic instructions like fetch_and_add vs. having to do a full CAS. The cache coherence traffic is no worse since everyone spins on one cache line in all implementations.

About

A small, fair, reader-writer ticket-based spinlock which allows many readers to acquire the lock at the same time while allowing only one writer at at time while preventing starvation of writers and readers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published