Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reader-Writer Synchronization

This Java program implements a solution to the classic reader-writer synchronization problem, giving priority to writer threads. It uses semaphores to ensure mutual exclusion and to control access to a shared integer buffer.

Author

Joseph Defendre

Description

The program creates multiple reader and writer threads, each attempting to read from or write to a shared buffer, respectively. Writers are given priority, meaning if both a reader and a writer are waiting to access the buffer, the writer goes first. The shared buffer is represented by a single integer.

Usage

To compile the program, run:

javac RW.java

To run the program, use the following command with the specified number of readers, writers, and the number of accesses for each thread:

java RW <# of readers> <# of writers> <# of access>

For example:

java RW 3 2 10

This command will start the program with 3 readers, 2 writers, and allow each thread to access the shared buffer 10 times.

Constraints

  • The program is designed to handle up to 5 readers and 5 writers.
  • Reader threads are named A, B, C, D, and E.
  • Writer threads are named F, G, H, I, and J.
  • Each writer will generate a positive integer less than 10 to write to the buffer.

Requirements

  • Java Runtime Environment (JRE) or Java Development Kit (JDK).

Note

This project is intended for educational purposes and demonstrates basic concurrency control in Java using semaphores.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages