Explain what is the purpose of mutex buffer_mutex

Assignment Help Data Structure & Algorithms
Reference no: EM132470625

Problem 1

A bakery shop has to provide a stream of muffins for customers. The muffins are made by a baker in the kitchen and placed on a conveyor belt. The conveyor belt carries the muffins to where the customers are waiting to buy them.

This scenario has been simulated using two processes: the baker and customer, and a shared conveyor belt implemented as a circular array called conveyor, where each space in the array can hold one muffin. There are two shared general semaphores, empty and full, and a mutex buffer_mutex. In this scenario, there is only multiple bakers and a single customer.

The pseudo-code for the baker is as follows. The baker makes use of an integer variable in for noting the next available space on the conveyor belt.
1. while(true){
2.   muffin = makeMuffin(); // Create a muffin
3.   wait(empty);
4.   wait(buffer_mutex);
5.   conveyor[in] = muffin; // Put the muffin on the conveyor belt
6.   in = (in + 1) mod n;
7.   signal(buffer_mutex);
8.   signal(full);
9. }

The pseudo-code for the customer is as follows. The customer makes use of an integer variable out for noting the next location on the conveyor belt that contains a muffin.
1. while(true){
2.   wait(full);
3.   muffin = conveyor[out]; // Get a muffin from the conveyor belt
4.   conveyor[out] = null;
5.   out = (out + 1) mod n;
6.   signal(empty);
7.   eat(muffin); // Eat the muffin
8. }

This code should be familiar to you as it is similar to the example of the Producer-Consumer problem. Only a few sentences are required for each of the Problems below.

Explain, in words, the purpose of the mod n statement. Explain what is the purpose of mutex buffer_mutex. What problems solves? You may wish to include simple examples.

Explain what will happen if the order of semaphores in the customer changes. So, we have in line 2  signal(empty) and in line 6  wait(full). Now assume that there is a single baker and a single customer, with an infinite buffer. Explain, in words, what changes should be made and why.

Problem 2
Some researchers are working in a lab. Due to safety regulations, only five people are allowed in the lab at the same time. The code for each researcher is given below. It uses a semaphore lab, to represent whether there is space left in the lab for more people. S1, S2 and S3 are labels identifying the line code.
Researcher code:
S1: wait(lab);
S2: work();
S3: signal(lab);

Part (1) There are eight researchers, A, B, C, D, E, F, G and H, working in the lab. Each researcher operates according to the above code. Your task is to give an execution trace that contains both of the following:

The trace should show what happens when there are less than five researches in the lab and one or more of them leave.
The trace should show what happens when there are five researchers in the lab and another researcher or several researchers want to enter.
The trace must start with an empty lab and show all the steps of each of the researchers as they enter/leave.
You must show the value of lab after each wait or signal step. Ensure that you state the initial value of lab.
If a wait operation executes, indicate whether the process succeeds or is placed in the queue. If a signal operation executes, indicate whether the value is changed or a sleeping process is woken up.
Each line of your trace should have the following format:
Statement executed including which Researcher process (e.g., M.S1 means that the researcher named M executed statement S1); the value of the lab semaphore (e.g., lab=2); whether the wait succeeded or was placed in the queue/ whether the signal changed the semaphore value or a sleeping process woke up.
For example: M.S1; lab=2; wait succeeded.

Part (2) The code has now been modified. Each time a researcher enters the lab, an integer totalEntered is incremented. The variable is initially 0. The new code is given below:
Researcher code:
S1: wait(lab);
S2: totalEntered = totalEntered + 1;
S3: work();
S4: signal(lab);

The code given has a problem. The researchers have found that sometimes the totalEntered value does not reflect the actual number of researchers who have entered the lab.

Explain, in words, how this situation could occur.

Show a trace that demonstrates the problem occurring. Note that you are not being asked to solve the problem.

Reference no: EM132470625

Questions Cloud

What are the consequences in duplicating an mpi : What are the consequences in duplicating an MPI?
Identify four general health risk problems that th exhibit : Identify four general health risk problems that T.H. exhibits. Identify a key factor in his family history that might have profound implications
Discuss implications of the illegal act by ultro management : Discuss the implications of this illegal act by Ultro's management. Describe the courses of action that are available to your CPA firm regarding this matter
Create a Statement of Changes in Shareholders Equity : On September 15, it sold the wholesale division to Dynamic Corporation. Create a Statement of Changes in Shareholders Equity
Explain what is the purpose of mutex buffer_mutex : Explain what will happen if the order of semaphores in the customer changes - Show a trace that demonstrates the problem occurring
Embolic in ineffective endocartis happens : A medicine to be offered to a patient 50 mcg per kg per minute; the patient weights 200 lbs. how much medicine per minute will the patient receive?
Determine the unit costs for any direct materials : Assume that there will be no change in unit costs for any direct materials, hourly wages will remain the same and employee benefits will continue at 20% of wage
Describe the sdoh that affect the family health status : Based on the information gathered through the family health assessment, recommend age-appropriate screenings for each family member.
What is the firm EVA at year-end : Miami Rivet had no other current liabilities. If the firm's after-tax percentage cost of capital is 9%, what is the firm's EVA at year-end

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Function that rotates a two-d array by ninety degree

Write and test the function that "rotates" 90° clockwise a two-dimensional square array of ints. For example, it would transform the array.

  Explain method for combining two trees-heap-order property

Assume two binary trees, T 1 and T 2 , hold entries satisfying heap-order property. Explain method for combining T 1 and T 2 into a tree T whose internal nodes hold union of entries

  Which data structure should be used for the given operations

Extract the event with smallest time-stamp (that is, determine the next event to process). Which data structure should be used for the above operations? Why?

  Write an algorithm that gets as input three data values

Write an algorithm that gets as input three data valuesx,y, andz and outputs the average of these values if the value ofx is positive.

  Describe greedy algorithm to make change consisting of dimes

Describe a greedy algorithm to make change consisting of quarters, dimes, nickels, and pennies. Prove that your algorithm yields an optimal solution.

  Write an algorithm for computing total flight time

Write an algorithm for computing total flight time and the horizontal distance traveled by the cannon ball for the problem discussed in class?

  Find an approximation to optimal traveling salesman route

We talked about the 'Nearest Neighbor1 algorithm as a way to find an approximation to the optimal Traveling Salesman route.

  Creating algorithm to implement function

Create an Algorithm to implement the given function and explain how the required task can be achieved in a step by step process.

  Create and test a class for a queue of objects

Your assignment is to create and test a class for a queue of objects. You may use any object class of your choice as the data for the queue.

  One e business failure

Discuss about one e-Business failure. Describe what happened and what you would have done differently. Explain whether or not the e-Business practiced sound financial planning.

  Create a report based on the query

Increase the font size of the Total Purchases by Customer label (in the strCustomerNameFooter section) to 11 and the =Sum calculated control to 10 points. Change the font color of both to dark blue.

  Evaluate benefits and disadvantages of each data structure

Evaluate the benefits and disadvantages of each data structure. Remember that the data structure selection can have an impact in the performance achieved.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd