What changes should be made and why

Assignment Help Data Structure & Algorithms
Reference no: EM132472234

Assignment Problem

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 questions below.

Q1: 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.

Q2: 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.

Reference no: EM132472234

Questions Cloud

What rate of return is built into the annuity : Receiving $3,500,000 today or a 20-year annuity of $250,000, with the first payment coming one year from today. What rate of return is built into the annuity
Show a trace that demonstrates the problem : Show a trace that demonstrates the problem occurring. Note that you are not being asked to solve the problem and The trace should show what happens when there a
How much could withdraw at the end of each of the next : Suppose you earned a $505,000 bonus this year and invested it at 8.25% per year. How much could you withdraw at the end of each of the next 20 years?
Describe the type of financial statement : Describe the type of financial statement information about these companies (separate or consolidated) that you would request.
What changes should be made and why : 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
What is the present value of the minimum lease payments : Rental of $210 per month (at end of each month). (The present value at 1% per month is $8,232.) What is the present value of the minimum lease payments
Prepare financial statements at the end of each month : Ming Chen began a professional practice on June 1 and plans to prepare financial statements at the end of each month. During June, Ming Chen
What is the effect on the financial statements : Revenue of $9,880 from the rental of equipment was earned but the customer had not yet paid. What is the effect on the financial statements
Producer-consumer problem : Explain what will happen if the order of semaphores in the customer changes and Explain what is the purpose of mutex buffer_mutex. What problems solves?

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  What will be the worst-case running time

Show all GUI components including frames, combo boxes, buttons and message dialog boxes - What will be the output when this program is executed

  Different network connections

Use your laptop at public store to check your email and discuss all the different network connections involved in this operation.

  Which algorithm uses fewer operations

Suppose that you have two different algorithms for solving a problem. To solve a problem of size n, the first algorithm uses exactly n22n operations.

  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

  Write methods that take a reference to binary tree root

Write efficient methods (and give their Big-Oh running times) that take a reference to a binary tree root T and compute-The number of leaves in T.

  Design an algorithm to determine best route for passenger

Consider the following problem: Design an algorithm to determine the best route for a subway passenger to take from one designated station to another in a typical urban subway system similar to those in San Francisco and New York

  For what values of d is the tree t

For what values of d is the tree T of the previous exercise an order -d B-tree? HINT: The definition of an order- d  deals with the minimum and maximum number of children an internal node can have.

  Write control structure-pseudocode algorithm for simple task

Three simple control structures which could be used to make this algorithm. What do you believe is most difficult part of creating algorithm?

  Identify the basic operation of the algorithm

Identify the basic operation of the algorithm and count number of times basic operation is performed by the algorithm, to confirm its predicted order of growth.

  Determine complete list of nodes which ancestor

Let the following tree: tree a. Determine the children of Q? b. What is the complete list of nodes which have D as ancestor? c. Determine the height of this tree (as height is defined in text)?

  Algorithm for finding the smallest number of coins

Consider the following coin changing problem. You are given a value N and an infinite supply of coins with values d1, d2, . . . , dk. Give an O(Nk) algorithm for finding the smallest number of coins that add up to the value N

  How cryptography can be properly and improperly used

The reason for this lab is to give you an understanding of how cryptography can be properly and improperly used, and how changes in technology may serve to weaken trusted cryptographic applications

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