CTEC2910 Concurrent and Parallel Algorithms Assignment

Assignment Help Data Structure & Algorithms
Reference no: EM132463610

CTEC2910 - Concurrent and Parallel Algorithms - De Montfort University

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 = makeMuf fin 0 ; // Create a muffin
3. wait (empty) ;
4. wait (buffer_mutex) ;
5. conveyor (in) = muffin; // Put the muffin on the conveyor beh
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.

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

(ii) 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 lob, to represent whether there is space left in the lao for more people. Sl, S2 and S3 are labels identifying the line code.

Researcher code:

S1: wait(lab);
S2: work();
S3: signal(lab);

(i) 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 lob 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.

(ii) The code has now been modified. Each time a researcher enters the lab, an integer totolEntered 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 totolEntered 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: EM132463610

Questions Cloud

Why use standard costs to control the costs of bus service : Why use standard costs to control the costs of the bus service?how to control the cost of the service bus without any price precision ?
Explain the meaning of the confidence interval : A random sample of 40 patients' records found a mean weight loss of 16.4 pounds with a standard deviation of 5.4 pounds.
Classifiy cash payment into what three category of activity : A statement of cash flows classifies cash receipts and cash payments into what three categories of activity? For each category of activity
What are the tax effects to the individual shareholders : What are the tax effects to the individual shareholders and corporation. compute the E&P, Taxable income and the tax effect to each shareholder from transaction
CTEC2910 Concurrent and Parallel Algorithms Assignment : CTEC2910 Concurrent and Parallel Algorithms Assignment Help and Solution, De Montfort University - Assessment Writing Service
Analyze the various positive impacts that biochips have : As a social scientist for the Office of Science and Technology, you have been tasked to analyze the various positive and negative impacts that Biochips.
Define how hackers benefit from stealing medical records : Write an essay of at least 500 words analyzing explaining how hackers benefit from stealing medical records. Use an example from the news.
What each shareholders recognized gain or loss : What's each shareholder's recognized gain or loss, what are each shareholder's basis in their shares and the company's basis in the assets.
What is the probability that two different versions : If four friends apply for licenses, what is the probability that two different versions will be used twice each (i.e. two of the friends will write one version

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