https://github.com/arkasarkar19/multi-reader-writer-with-synchronization
Refer Readme.md
https://github.com/arkasarkar19/multi-reader-writer-with-synchronization
client-server-architecture mutex-synchronisation operating-system reader-writer semaphores-locking shared-memory threading
Last synced: 3 months ago
JSON representation
Refer Readme.md
- Host: GitHub
- URL: https://github.com/arkasarkar19/multi-reader-writer-with-synchronization
- Owner: ArkaSarkar19
- Created: 2019-12-11T18:41:40.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-18T07:55:01.000Z (almost 5 years ago)
- Last Synced: 2025-01-19T07:15:13.356Z (4 months ago)
- Topics: client-server-architecture, mutex-synchronisation, operating-system, reader-writer, semaphores-locking, shared-memory, threading
- Language: C
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Multi-reader-writer-with-Synchronization
### IMPLEMENTATION
* I have Implemented mlti Reader Writer with synchronization (no race conditions ). The code is in C.The **main.c** file handles every operation of writers and readers, the **rw.c** file has a
client-server relationship with main.c.The global shared queue is an array which keeps two pointers front & rear for the shared
queue, each element of this shared queue can be accessed via multiple threads at the
same time hence each element has locks in a form of a **binary semaphore** (r2_mutex)
ensuring no race conditions.Since only one write can update the queue at a certain moment a binary semaphore
write_mutex which ensures no other reader or writer can access the queue at that point
in time. Similarly dequeuing & enqueuing is also atomic among readers/writers hence
binary semaphore **deq_mutex & enq_mutex** is implemented to ensure the same.To ensure multiple readers can read a certain element concurrently, r_num is implement
which stores the number of threads accessing a certain element, also r1_mutex is
implemented to ensure there are no race conditions in r_num.
Main.c spawns new threads for every reader and writer and waits for user commands from rw.c.### COMPILE AND TEST
* To compile use command ‘make’
* ./main to run the server (MUST BE STEP 1)
* ./rw to run reader or writers
* Ensure that only one main is running.
* Once main program is running, on a new terminal run the rw program. The program can handle almost 100 readers and 100 writers.### USER INPUTS
* For writer :
* To enqueue enter (1) followed by the element to be enqueued
* To overwrite enter (2) followed by the index of the array to be overridden.
$ Select Operation to be performed
1 - overwrite data
2 - enqueue data
* For reader:
* To read a certain element from queue enter (1) followed by the index
* To dequeue a element from queue enter (2)
Select Operation to be performed
1 - read data
2 - dequeue data
### EXPECTED OUTPUT
Once given the command the program prints out the output of the program to the
corresponding terminal running it.### ERROR HANDLING
* Prompts the user if index requested for any operation is out of bounds of the queue followed by an error message
* Doesn’t allow writer to enqueue to a full queue.
* Doesn’t allow reader to dequeue an empty queue.
* Prompts if user enters anything other than 1 or 2 to request operations for readers and writers.