Consider the below pseudocode where 5 philosophers are implemented as threads that run phl: int status[5];...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the below pseudocode where 5 philosophers are implemented as threads that run "phl": int status[5]; // all equals to 1 (thinking) -- can be 0 (ready to eat), 1 (thinking), 2 (eating) semaphore mtx; // equals to 1 semaphore p[5]; // all equals to 0 void phl(int index) { while(1) { think(); takefork(index); eat()); putfork(index); } } void takefork(int index) { wait(mtx); status[index]=0; test(index); signal(mtx); wait(p[index]); } void putfork (int index) { wait(mtx); status[index] = 1; } test(left_side(index)); test(right_side(index)); signal(mtx); int left_side(int index) { return (index + 4) % 5; } int right_side(int index) { return (index + 1) % 5; } void test(int index) { if (status[index]= 0 && status[left_side(index)] !=2 && status[right_side(index)] !=2) { status[index] = 2; signal(p[index]);} Briefly describe a scenario where starvation is observed. Suggest a modification to the code in order to address starvation. Consider the below pseudocode where 5 philosophers are implemented as threads that run "phl": int status[5]; // all equals to 1 (thinking) -- can be 0 (ready to eat), 1 (thinking), 2 (eating) semaphore mtx; // equals to 1 semaphore p[5]; // all equals to 0 void phl(int index) { while(1) { think(); takefork(index); eat()); putfork(index); } } void takefork(int index) { wait(mtx); status[index]=0; test(index); signal(mtx); wait(p[index]); } void putfork (int index) { wait(mtx); status[index] = 1; } test(left_side(index)); test(right_side(index)); signal(mtx); int left_side(int index) { return (index + 4) % 5; } int right_side(int index) { return (index + 1) % 5; } void test(int index) { if (status[index]= 0 && status[left_side(index)] !=2 && status[right_side(index)] !=2) { status[index] = 2; signal(p[index]);} Briefly describe a scenario where starvation is observed. Suggest a modification to the code in order to address starvation.
Expert Answer:
Answer rating: 100% (QA)
Each philosopher is represented by a thread There are five semaphoresone for each fork and one mutex The status array keeps track of the state of each philosopher thinking hungry eating The takefork f... View the full answer
Related Book For
Systems Analysis And Design
ISBN: 978-1119496489
7th Edition
Authors: Alan Dennis, Barbara Wixom, Roberta M. Roth
Posted Date:
Students also viewed these programming questions
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Bhushan Building Supplies entered into the following transactions. Prepare journal entries under the perpetual inventory system. June 1 Purchased merchandise on account from Brij Builders Materials,...
-
1. Refer to Exercise 27. Suppose that a batch of 99 pea plants contains 33 plants of each of the three genotypes. Refer to Exercise 27, Traits passed from generation to generation are carried by...
-
Each of the items below must be considered in preparing a statement of cash flows for Baskerville Co. for the year ended December 31, 2014. For each item, state how it should be shown in the...
-
A ball is thrown vertically upward. (a) As it moves upward, it slows down under the influence of gravity. Considering the changes in energy of the ball, is the work done by Earth on the ball positive...
-
The Pacific Corporation operates car rental agencies at more than 20 airports. Customers can choose from one of three contracts for car rentals of one day or less: Contract 1: $50 for the day...
-
Which OSI layer is responsible for connection - oriented communication?
-
In this mini-case you will perform some procedures required as a part of audit planning. For ease your audit manager has already organized the workpapers and completed several of the required...
-
4. You've got a great opportunity to give a positive verbal recommendation for a current employee applying for a job in another department of your company. You don't believe this is a case of an...
-
create the classic game of hangman. Your program will randomly pick from a pool of words for the user who will guess letters in order to figure out the word. The user will have a limited number of...
-
How do consolidations and acquisitions (M&A) influence corporate money for a situation study, and what are the vital variables and contemplations that organizations ought to consider while taking...
-
our cousin Jeremy has asked you to bankroll his proposed business painting houses in the summer. He plans to operate the business for 5 years to pay his way through college. He needs $5000 to...
-
I am learning to program a game engine which is why I followed a tutorial, with that tutorial I have gotten this far and even though my code is identical to theirs (theirs did work in the videos) its...
-
b Employer identification number (EIN) 26-3356489 c Employer's name, address, and ZIP code General Motors LLC 9832 Detroit Way Detroit, MI 54569 d Control number e Employee's first name and initial...
-
t ue illustrate sampling variabili popu. in a small sample from a small chooses five players at random to re ceive a new scholarship funded by alumni. Richvalsky* Betsa Blanco Romero Christner...
-
How can a promoter avoid personal liability for pre-incorporation contracts?
-
What do you think are three common mistakes made by novice systems analysts in preparing user documentation?
-
Think about the system that your university currently uses for career services and pretend that you are in charge of replacing the system with a new one. Describe how you would decide on the...
-
Discuss the issues the project manager must consider when assigning programming tasks to the programmers.
-
Explain the properties of the restricted least squares estimator. In particular, how do its bias and variance compare with those of the unrestricted, ordinary, least squares estimator?
-
Explain the concept of a control variable and the assumption necessary for a control variable to be effective.
-
From output of your computer software, locate (a) the sum of squared errors, (b) the \(F\)-value for the overall significance of a regression model, (c) the estimated covariance matrix for the least...
Study smarter with the SolutionInn App