In this lab you will simulate one of the classical synchronization problems in order to see how the (semi) critical section problem could be implemented using binary and counting semaphores. 5 processes are characterized by 3 readers and 2 writers. Up to two reader processes can be inside their critical section without any writer process. For writer process to go into its critical section, it should check whether there is any reader or writer process is in the critical section. Critical section in this problem is reading shared data buffer for reader processes and updating shared data buffer for writer processes. It is optional to implement real shared data for readers and writers but vou have cifu clearly following thing ur cample

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please code in C++

### Lab Overview

In this lab, you will simulate one of the classical synchronization problems to understand how the (semi) critical section problem can be implemented using binary and counting semaphores.

### Process Description

- **Processes Involved**: 3 readers and 2 writers.
- **Reader Processes**: Up to two reader processes can be within their critical section simultaneously without any writer process present.
- **Writer Processes**: Before entering its critical section, a writer process should check for the presence of any reader or writer process already in the critical section.

### Critical Section Behavior

The critical section involves:
- **Reading** from a shared data buffer for reader processes.
- **Updating** the shared data buffer for writer processes.

Implementing real shared data for readers and writers is optional. However, your output must clearly demonstrate:
- When any reader or writer process enters its critical section, it must report the presence of other readers or writers.
- (Optional) You may print the data read or written if implementing a real buffer.
- Implement a function to generate "Panic Messages" if the rules of this semi-critical section problem are not followed. A correct solution should not trigger these messages.

### Main Program Execution

- Utilize a random number generator to select processes for execution.
- Each selected process performs one instruction before returning control to the main function.
- The subsequent process is chosen by another random number generation. Ensure each process executes exactly one instruction before resuming, maintaining its state for future execution.

### Implementation Guidelines

- Implement using a `switch` statement in C or C++.
- Avoid using multithreading or mutex lock features inherent to the programming language.
- Each process (reader or writer) should be handled within a single big `switch` statement and returned after each instruction. Maintain a global program counter for each process to ensure accurate resumption.

### Subprojects

- **Subproject 1**: Implement this with **binary and counting semaphores**.
- **Subproject 2**: Implement this with **testandset function**.
Transcribed Image Text:### Lab Overview In this lab, you will simulate one of the classical synchronization problems to understand how the (semi) critical section problem can be implemented using binary and counting semaphores. ### Process Description - **Processes Involved**: 3 readers and 2 writers. - **Reader Processes**: Up to two reader processes can be within their critical section simultaneously without any writer process present. - **Writer Processes**: Before entering its critical section, a writer process should check for the presence of any reader or writer process already in the critical section. ### Critical Section Behavior The critical section involves: - **Reading** from a shared data buffer for reader processes. - **Updating** the shared data buffer for writer processes. Implementing real shared data for readers and writers is optional. However, your output must clearly demonstrate: - When any reader or writer process enters its critical section, it must report the presence of other readers or writers. - (Optional) You may print the data read or written if implementing a real buffer. - Implement a function to generate "Panic Messages" if the rules of this semi-critical section problem are not followed. A correct solution should not trigger these messages. ### Main Program Execution - Utilize a random number generator to select processes for execution. - Each selected process performs one instruction before returning control to the main function. - The subsequent process is chosen by another random number generation. Ensure each process executes exactly one instruction before resuming, maintaining its state for future execution. ### Implementation Guidelines - Implement using a `switch` statement in C or C++. - Avoid using multithreading or mutex lock features inherent to the programming language. - Each process (reader or writer) should be handled within a single big `switch` statement and returned after each instruction. Maintain a global program counter for each process to ensure accurate resumption. ### Subprojects - **Subproject 1**: Implement this with **binary and counting semaphores**. - **Subproject 2**: Implement this with **testandset function**.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education