Skip to content

dionisiydk/ReadWriteLock

 
 

Repository files navigation

ReadWriteLock

Build Status

It's implementation of reentral read write lock which described in https://en.wikipedia.org/wiki/Readers–writer_lock. From the article:

A ReadWriteLock allows concurrent access for read-only operations, while write operations require exclusive access. This means that multiple threads can read the data in parallel but an exclusive lock is needed for writing or modifying data. When a writer is writing the data, all other writers or readers will be blocked until the writer is finished writing.

Installation

Metacello new
  baseline: 'ReadWriteLock';
  repository: 'github://pharo-ide/ReadWriteLock';
  load

Use following snippet for stable dependency in your project baseline:

spec
    baseline: 'ReadWriteLock'
    with: [ spec repository: 'github://pharo-ide/ReadWriteLock:v1.0.0' ]

Public API and Key Messages:

lock := ReadWriteLock new.
lock criticalRead: ["read code"].
lock criticalWrite: ["write code"]

Main difficulty is carefully handle process termination during execution of critical sections. This problem described in Semaphore>>critical: comment. Same approach is used here. But synchronization logic around two semaphores for reading and writing complicates things very much. No simple way to decompose logic on methods because information about process interruption become hidden.
From Semaphore comment:

The main trick is assignment right before we go into the wait primitive (which is not a real send and therefore not interruptable either). So after we can check that waiting is happen or not.

About

Implementation of reentral read write lock which described in https://en.wikipedia.org/wiki/Readers–writer_lock.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Smalltalk 99.5%
  • HTML 0.5%