Producer-consumer problem

Assignment Help Data Structure & Algorithms
Reference no: EM132472230

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: EM132472230

Questions Cloud

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?
Determine the variable cost per unit : Using the high-low method, determine the variable cost per unit and the total fixed cost. Round all answers to the nearest whole dollar
Prepare journal entries for infinity inc : On March 31, 2018, Infinity received a dividend of $0.50 per share on its Ioniq shares. Prepare journal entries for Infinity Inc. for its investment in Ioniq
Calculate the gain or loss on the partial retirement of bond : Calculate the gain or loss on the partial retirement of the bonds on August 1, 2021. Do an amortization schedule for the first 2 years of the bond issue.
What would the average cost of ms-drg : Using these data, Determine how many patients must be seen each day, assuming a 365-day operation, to reach the break-even point?

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Add a delete operation to the heap adt that can be used

Add a delete operation to the Heap ADT that can be used to delete an item anywhere in the heap.

  Give an algorithm that returns the position

Give an algorithm that returns true if a string contains properly nested and balanced parentheses, and false if otherwise. Hint: At no time while scanning a legal string from left to right will you have encountered more right parentheses than left..

  Write java windowed application to generate maths speed

COIT20256 - Data Structures and Algorithms - write a Java windowed application to generate a maths speed test that students can use to sharpen their arithmetic

  Develop and explain at least five different visualizations

DATA 610 - Decision Management Systems Assignment - Exploratory Data Analysis (EDA) using Cognos Analytics, University of Maryland University College, USA

  Create divide and conquer algorithm to solve problem

Create a divide and conquer algorithm to solve problem. The time complexity of your algorithm must be O(nlgn) or better.

  Binary search tree adt

Write a client method that returns a count of the number of nodes in a binary search tree that contain a value less than or equal to the argument value.

  What is the worst-case running time of algorithm a

Algorithm A executes an O(logn)-time computation for each entry of an n-element array. What is the worst-case running time of Algorithm A?

  Explain the difference between a state graph and search tree

Such a system can be described through a state graph or a search tree. Explain and elaborate on the difference between a state graph and a search tree.

  Search a sorted array of floating point numbers

You need to write a program which uses binary search to search a sorted array of floating point numbers - Create an array of doubles, using the following statement. Notice that the array is sorted.

  What is big-oh running time for an arraylist and linkedlist

The RandomAccess interface contains no methods but is intended to serve as a marker: a List class implements the interface only if its get and set methods.

  Do the planning and write an algorithm to solve the problem

Do the planning and write an algorithm to solve the problem

  Find efficiency of high speed digital transmission system

Assume I have a multiplexer that is connected to a high speed digital transmission system that can transfer 1,536,000 data bits per second.

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