Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Readers-Writers Lock (Java)

A Java implementation of the classic second readers-writers problem, using semaphores to allow concurrent read access while giving writers priority (preventing writer starvation).

Design

  • S — binary semaphore guarding the shared resource.
  • mutex — binary semaphore protecting the reader count.
  • serviceQueue — a fair (FIFO) binary semaphore ("turnstile") that readers must also pass through before acquiring mutex — this is what prevents writers from starving under a steady stream of readers.
  • readCount — tracks how many readers currently hold the resource; only the first reader acquires S, and only the last reader releases it.

API

  • readLock() / readUnLock() — acquire/release read access
  • writeLock() / writeUnLock() — acquire/release exclusive write access

Tech stack

Java (java.util.concurrent.Semaphore)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages