Explain the purpose of the mod n statement

Assignment Help Data Structure & Algorithms
Reference no: EM132467153

Data Structure & Algorithms Question -

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.

Part A - 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.

Part B - 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: EM132467153

Questions Cloud

MKT301 - Consumer Behavior Assignment : MKT301 - Consumer Behavior Assignment Help and Solution - Emirates College of Technology, UAE. Identify the target audience that you are trying to reach
What way does the globalization of communication affect : Identify the main religious idea. In what way does the globalization of communication affect the way we understand religion as a culture?
What is the bond price if the bond yield to maturity : What is the bond's price if the bond's yield to maturity is 9 percent?
Explain how the style and specific visual characteristics : Explain how the style and specific visual characteristics of each painting contributed to or reflected its overall religious context or meaning
Explain the purpose of the mod n statement : Explain, in words, the purpose of the mod n statement. Explain what is the purpose of mutex buffer_mutex. What problems solves
How did caesar use thetechnology to advantage : What does Caesar's description, in The Gallic War, reveal about the technology of war at the time? How did Caesar use this technology to his advantage?
Area of financial planning : The above scenarios are not "complete" pictures but are a good step in the process of completing topical financial plans. State a few investment products
Purchase a derivative security that makes payments : You you advise her to use all of her capital to purchase a derivative security that makes payments
Show a monthly cash flow statement for kira : a) Show a monthly cash flow statement for Kira. b) Show a net worth statement for Kira.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

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