readers-writer v1.0.6

A simple readers writer lock for crystal lang
  • v1.0.6 - September 17, 2020
  • v1.0.5 - May 22, 2019
  • v1.0.4 - May 20, 2019
  • v1.0.3 - May 20, 2019

Readers Writer Lock

Build Status

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

  1. Add the dependency to your shard.yml:

    dependencies:
      rwlock:
        github: spider-gazelle/readers-writer
    
  2. 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

Owner
github statistic
  • 3
  • 3
  • 0
  • 0
  • about 1 month ago
  • May 20, 2019
License

MIT License

Links
Synced at

Mon, 19 Oct 2020 13:32:15 GMT