Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective: In completion of this program, you will understand one of the three requirements for solving a critical section problem. This requirement is Progress. Progress

image text in transcribed
image text in transcribed
Objective: In completion of this program, you will understand one of the three requirements for solving a critical section problem. This requirement is Progress. Progress is when if no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely. The program will show how multiple processes can handle the same shared variables without conflicting with each other. Write a C/C++ program implementing two Critical Sections. In order to accomplish this, you will create three processes. These 3 processes will execute 2 functions, each with a critical section. You will need to print out the Process ID of the process in control of each critical section. Function 1 will: Within the critical section, iterate a counter from 1 to 10, printing out the value of each counter for each iteration on the same line separated by a space. Outside the critical section, sleep for one second. This can be done with the code std::this_thread::sleep_for (std::chrono:: seconds (1)); Function 2 will: Within the critical section, spell out the letters of the alphabet, printing out each letter on the same line separated by a space. (This can be done with a for loop) Outside the critical section, sleep for one second. This can be done with the code std::this thread::sleep_for (std::chrono: :seconds (1)); To create a critical section, you will need to lock and unlock the code with a mutex (std::mutex). In the main function, wait for each process to complete and print out that the process has completed. To run this CPP program on Unix or Linux, type: g++ -pthread -std=C++11 progl.cpp Sample Output NOTE: You will notice that since each process sleeps after completing a function, the next process will begin to execute and grab hold of the critical section. Process 1001 counting to 10 1 2 3 4 5 6 7 8 9 10 Process 1002 counting to 10 1 2 3 4 5 6 7 8 9 10 Process 1003 counting to 10 1 2 3 4 5 6 7 8 9 10 Process 1001 spelling the alphabet ABCDEFGHIJKLMNOPQR S T U V W X Y Z Process 1002 spelling the alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ Process 1003 spelling the alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ --Process P1 Completed--- --Process P2 Completed --- ---Process P3 Completed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

13-4 What are alternative methods for building information systems?

Answered: 1 week ago