Apply standard concurrent algorithm design patterns

Assignment Help Other Subject
Reference no: EM132956514 , Length: word count:1300

CTEC2910 Concurrent and Parallel Algorithms - De Montfort University

Learning outcome 1: Analyse specific programming language and library support for the development of concurrent programs
Learning outcome 2: Apply standard concurrent algorithm design patterns

Objectives
The objective of this assessment is for you to demonstrate your understanding of issues related to the design and use of concurrent algorithms.

Question 1
A sushi shop provides a stream of sushi for customers. The sushi are made by a chef in the kitchen and placed on a conveyor belt. The conveyor belt carries the sushi to where the customers are waiting to buy them.
This scenario has been simulated using two processes: the chef and the customer, and a shared conveyor belt implemented as an array called conveyor with finite size, where each space in the array can hold one sushi. In this scenario, there is only a single chef and a single customer.
The pseudo-code for the chef is as follows.
1. while(true){
2. sushi = makeSushi(); // Create a sushi
3. wait(empty);
4. wait(buffer_mutex);
5. conveyor[in] = sushi; // Put the sushi on the conveyor belt
6. in = in + 1;
7. signal(buffer_mutex);
8. signal(full); 9. }

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.
(a) The pseudo-code for the chef has an error(s). Propose the solution by giving the correct code and explain the reason in few sentences.

(b) Give the pseudo-code for the customer.

(c) Now assume that there is a single chef and a single customer, with a conveyor belt of infinite size. Give the pseudo-code for this scenario, both for the chef and customer.

Question 2

There is a self-service car wash that has four washing places, so only four drivers can wash their car at the same time. The code for each driver is given below. It uses a semaphore carwash, to represent whether there is space left in the car wash for more drivers. S1, S2, and S3 are labels identifying the line code.
Driver code:
S1: wait(carwash); S2: wash();
S3: signal(carwash);
(a) There are six drivers, A, B, C, D, E, and F that want to wash their car. Each driver 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 four drivers in the car wash and one or more of them leave.
• The trace should show what happens when there are four drivers in the carwash and another driver, or several drivers want to enter.
The trace must start with an empty car wash and show all the steps of each of the drivers as they enter/leave.
You must show the value of carwash after each wait or signal step. Ensure that you state the initial value of carwash.
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 Driver process (e.g., M.S1 means that the driver named M executed statement S1); the value of the carwash semaphore (e.g., carwash=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; carwash=2; wait succeeded.

(b) The code has now been modified. Each time a driver enters the car wash, an integer totalEntered is incremented. The variable is initially 0. The new code is given below:
Driver code:
S1: wait(carwash);
S2: totalEntered = totalEntered + 1; S3: wash();
S4: signal(carwash);
The code given has a problem. The drivers have found that sometimes the totalEntered value does not reflect the actual number of drivers who have entered the car wash.
• 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

Attachment:- Concurrent and Parallel Algorithms.rar

Reference no: EM132956514

Questions Cloud

What is the price of a call option : Given a 3-month put price is 4.5 at strike price of 57.5 on an asset that is currently trading at 55.17. Assume risk free rate to be 7%.
Explain production process : If you are a manufacturing company, how will you treat the product and material losses incurred during the production process? How are these losses going to aff
How do you form a protective put : How do you form a protective put? What is your maximum profit when you sell a straddle?
Difference between payoff and profit of an option : What is the difference between payoff and profit of an option? Which line (payoff, profit) should be lower when you draw the two lines on the graph for a long c
Apply standard concurrent algorithm design patterns : Analyse specific programming language and library support for the development of concurrent programs and Apply standard concurrent algorithm design patterns
What the amount of the depreciation expense for : What The amount of the depreciation expense for 2021 is? As of Jan. 1, 2021, Dignity Corp. decided to change the method of computing depreciation
How much depreciation should gentleness record : How much depreciation should Gentleness record in 2021 for this asset? Gentleness Company takes a full year's depreciation in the year
Calculate diluted earnings per share for mnc berhad : Calculate Diluted earnings per share (EPS). MNC Berhad had recorded RM2,000,000 net income after tax. The company currently has RM4, 000,000
Prepare an appropriate inventory record for Product : A stocktake on 30 June revealed 7,700 units in inventory. Prepare an appropriate inventory record for Product EF5089 for June

Reviews

Write a Review

Other Subject Questions & Answers

  Cross-cultural opportunities and conflicts in canada

Short Paper on Cross-cultural Opportunities and Conflicts in Canada.

  Sociology theory questions

Sociology are very fundamental in nature. Role strain and role constraint speak about the duties and responsibilities of the roles of people in society or in a group. A short theory about Darwin and Moths is also answered.

  A book review on unfaithful angels

This review will help the reader understand the social work profession through different concepts giving the glimpse of why the social work profession might have drifted away from its original purpose of serving the poor.

  Disorder paper: schizophrenia

Schizophrenia does not really have just one single cause. It is a possibility that this disorder could be inherited but not all doctors are sure.

  Individual assignment: two models handout and rubric

Individual Assignment : Two Models Handout and Rubric,    This paper will allow you to understand and evaluate two vastly different organizational models and to effectively communicate their differences.

  Developing strategic intent for toyota

The following report includes the description about the organization, its strategies, industry analysis in which it operates and its position in the industry.

  Gasoline powered passenger vehicles

In this study, we examine how gasoline price volatility and income of the consumers impacts consumer's demand for gasoline.

  An aspect of poverty in canada

Economics thesis undergrad 4th year paper to write. it should be about 22 pages in length, literature review, economic analysis and then data or cost benefit analysis.

  Ngn customer satisfaction qos indicator for 3g services

The paper aims to highlight the global trends in countries and regions where 3G has already been introduced and propose an implementation plan to the telecom operators of developing countries.

  Prepare a power point presentation

Prepare the power point presentation for the case: Santa Fe Independent School District

  Information literacy is important in this environment

Information literacy is critically important in this contemporary environment

  Associative property of multiplication

Write a definition for associative property of multiplication.

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