Order of semaphores in the customer changes

Assignment Help Data Structure & Algorithms
Reference no: EM132472563

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 (a) 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.

(b) 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: EM132472563

Questions Cloud

How can apply the concepts of accrual and cash accounting : Prepare transaction and share with the group how it would be accounted for under both the accrual method and the cash methods of accounting.
Epidemiology Paper Topic - Sexually Transmitted Diseases : Epidemiology Paper Assignment - Topic - Sexually Transmitted Diseases. Identify potential obstacles that may hinder the implementation of the prevention
Determine the gross profit for april and ending inventory : Determine the gross profit for April and ending inventory on April 30 using the first-in, first-out (FIFO); last-in, first-out (LIFO)
What are some of the benefits of using accrual accounting : Determine Why does accountants use this instead of the cash basis of accounting? And also Determine What are some of the benefits of using accrual accounting?
Order of semaphores in the customer changes : Explain what will happen if the order of semaphores in the customer changes - Explain, in words, what changes should be made and why
401077 Introduction to Biostatistics Assignment : 401077 Introduction to Biostatistics Assignment Help and Solution, Western Sydney University, Australia. Critically appraise of statistical material in paper
How do determine the deferred tax assets : How do determine whether there are deferred tax assets and deferred tax liabilities within a companies annual report? And then to understand the factors
Determine bank reconciliation for stewart recording studio : In reviewing cheques returned by the bank, the bookkeeper discovered that cheque, Prepare the bank reconciliation for Stewart Recording Studio at April 30
What is the difference in cash flow between the two firms : What is the difference in cash flow between the two firms? Given that the tax rate is 40 percent, compute the cash flow for both companies.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Finding majority element

Let A be an array of n elements. An element x is said to be a majority element in A if it occurs in A more than n/2 times.

  How long do es a value take to transit the entire pipeline

Construct a pipeline that connects an arbitrary number of goroutines with channels. What is the maximum number of pipeline stages you can create without running out of memory? How long do es a value take to transit the entire pipeline?

  Store the grades that you read in an arraylist

We expect the file to contain grades represented by integer values, one per line. If you encounter a value that is not an integer, you should throw an exception, print a message to the console, skip that value, and continue processing.

  Database design

As with the previous exams(SQL,E-R diagram and Normalization, you may complete this assignment at any time up to its due date of December 8, 2013.

  Time sharing operating system

Assume a time sharing operating system allocated time slices of twenty milliseconds and the machine executed an average of 5000 instructions per microsecond.

  Create an algorithm to describe how to balance a checkbook

Create an algorithm to describe how to balance a checkbook for a company that has more than 100transactions.

  Create a visual logic file to execute the given task

Create a Visual Logic file to execute the task. Create an Excel Macro to execute that accomplishes the same calculation task as the Visual Logic file.

  Create an idef1x entity relationships diagram

The Metropolitan Housing Agency is a non profit corporation that advocates the development and improvement of low income housing.

  Calculate the cost of installing fiber optic cable

Write a program that will calculate the cost of installing fiber optic cable at a cost of $0.87 per foot for a company. Your program should display the company name and the total cost

  Determine the height of the tree

COSC 2007 -Data Structures - determine the height of the tree, and find each value. You do not need to output the tree using the inorder traversal, but it might be a useful method for you during debugging. Run the program on the two sets of intege..

  Concept learninga write an algorithm called find-g to nd a

concept learninga write an algorithm called find-g to nd a maximally-general consistent hypothesis. you can assume the

  Describe the use of a binary tree when searching for keys

question 1 discuss the use of a binary tree when searching for keys in an array. question 2 discuss the use of a binary

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