# Concurrent and Parallel Algorithms

Question 2

There is a public swimming pool with a limit of 4 swimmers in the pool at one time. (It is a very small pool!) The code for each swimmer is given below. It uses a semaphore poolSpace, to represent whether there is space left in the pool for more swimmers. S1, S2 and S3 are labels identifying the line of code. Swimmer code: S1: wait(poolSpace); S2: swim(); S3: signal(poolSpace);

(a) There are six people, A, B, C, D, E and F who want to swim in the pool. Each person is an instance of the Swimmer class. Demonstrate how the semaphore prevents more than four people being in the pool at the same time by giving an example execution trace. Show the value of poolSpace after each wait or signal step. Ensure that you state the initial value of poolSpace. 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 Swimmer process (e.g. A.S1); poolSpace value (e.g. poolSpace=2); whether the wait succeeded or was placed in the queue/ whether the signal changed the semaphore value or a sleeping process woke up. (b) The swimmers have become more competitive. They want to keep track of the fastest time to swim a length of the pool. They decide to use the code below, which uses a shared variable fastest to record the fastest time (i.e. smallest value) so far.

Assume that when the method swim runs, it updates the Swimmer’s local int variable myTime to the time just taken for this current swim. The details of how it does this is irrelevant. Global shared variable: int fastest; Swimmer code: wait(poolSpace); swim(); if (fastest > myTime){ fastest = myTime; } signal(poolSpace); The code given has a problem. The swimmers have found that sometimes the time stored in fastest is not actually the quickest time so far. 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. You can select any arbitrary times for myTime for each swimmer as long as it demonstrates how the problem occurs.

#Concurrent #Parallel #Algorithms

Pages (275 words)
Standard price: \$0.00

### Latest Reviews

Impressed with the sample above? Wait there is more

Related Questions

### 1.Accountability is increasingly a focal point in public administration. How

1.Accountability is increasingly a focal point in public administration. How are public agencies subjected to greater accountability than the private and non-profit sectors? Is this

### Course Name Cryptography In the second milestone writing assignment you will analyze asymmetric and symmetric encryption. Evaluate the differences between

Course Name CryptographyIn the second milestone writing assignment, you will analyze asymmetric and symmetric encryption. Evaluate the differences between the two of them and which

### DISCUSSION 1 Respond to the following questions in a minimum

DISCUSSION 1 Respond to the following questions in a minimum of 175 words: What is one new feature or function related to spreadsheets that you

### Explain the ways in which the Italian Renaissance in Florence was a rebirth of the GrecoRoman classical beliefs and practices.

Explain the ways in which the Italian Renaissance in Florence was a rebirth of the Greco-Roman classical beliefs and practices. To support your response, please

### When you begin working as a medical biller or coder,

When you begin working as a medical biller or coder, you may be required to use HCPCS Level II codes. With that in mind, consider

### I will send all my assignments Paper: In week 1 of this course you were asked to identify a business

(I will send all my assignments)Paper:In week 1 of this course you were asked to identify a business that interests you. Throughout this course you

### Refer to your in-progress persuasive essay draft. You may find

Refer to your in-progress persuasive essay draft. You may find it helpful to make revision notes on your draft as you work on this

### Based on your own interest, choose a contemporary management issue.

Based on your own interest, choose a contemporary management issue. Locate four related peer-reviewed articles. Prepare a summary of your readings and IEE statements that

Answering for each question. 1. What is your philosophy of education and the purpose of schooling? 2. Explain, using citations, how Confucius, Maxine Greene, and

### For our final discussion: Describe the three important marketing concepts you

For our final discussion: Describe the three important marketing concepts you learned about in this course. Explain why these concepts will be useful to

### Powerpoint presentation 10-15 slides not including title slide and reference

Powerpoint presentation 10-15 slides not including title slide and reference slide, with 150-300-word speaker notes for each slide. APA 6, in-text citation, Cite at least

### Computer users have mixed feelings about software piracy. In one

Computer users have mixed feelings about software piracy. In one survey, 78 percent of respondents agreed that software should not be copied illegally, but 47

New questions