readers-writer v1.0.7
Readers Writer Lock
Allows any number of concurrent readers, but only one concurrent writer (And while the "write" lock is taken, no read locks can be obtained either) Access is fair. (read, write, read, write requests will occur in the order they arrived.)
Installation
-
Add the dependency to your
shard.yml
:dependencies: rwlock: github: spider-gazelle/readers-writer
-
Run
shards install
Usage
require "rwlock"
balance = 10
rwlock = RWLock.new
# Reading the balance
rwlock.read { puts balance.inspect }
# Modifying
rwlock.write { balance += 10 }
rwlock.synchronize { balance += 10 }
# Reentrant
rwlock.read do
rwlock.write { balance = 100 } if balance > 100
end
Repository
readers-writer
Owner
Statistic
- 5
- 0
- 0
- 6
- 0
- over 3 years ago
- May 20, 2019
License
MIT License
Links
Synced at
Sat, 23 Nov 2024 01:27:48 GMT
Languages