Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C++ solving two critical sections. First, create three processes. These three processes will execute two functions, each with a critical section. Print out the

Using C++ solving two critical sections. First, create three processes. These three processes will execute two functions, each with a critical section. Print out the process ID of the process in control of each critical section.

Function 1: in the critical section, iterate a counter from 1-10 print out the value of each counter for each iteration on the same line.

Outside the critical section, sleep for one-second use this code : std::this_thread::sleep_for(std::chrono::seconds(1));

Function 2: in the critical section, spell out the letters of the alphabet, printing out each letter on the same line separated.

Outside the critical section, sleep for one-second use this code : std::this_thread::sleep_for(std::chrono::seconds(1));

To create a critical section use mutex(std::mutex) to lock and unlock the code.

Main Function waits for the process to complete and print out the process has completed.

The Output should look like this:

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:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Process 1002 spelling the alphabet:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Process 1003 spelling the alphabet:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

--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 with AI-Powered 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

Students also viewed these Databases questions