1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
barxatty [35]
3 years ago
6

Playville is a tiny town in fictional middle earth, which is inhabited by dwarves and elves. Playville has a playground to which

dwarves and elves go if they wish to play. The sporting rules of Playville state that a play can take place only if either there are 5 dwarves or 3 elves present to play. If the playing condition is not met (i.e., 5 dwarves or 3 elves are not present at the playground), an arriving person (dwarf or elf) has to wait in their respective waiting area near the playground. When either the dwarves or the elves have their quorum, they move on to the playground to play, if the playground is already not in use. The playground, at any time, is either empty or it is occupied by playing dwarves or it is occupied by playing elves.
After a dwarf or elf team has played to its satisfaction, it leaves the ground. Assume all dwarves are identical to each other, and all elves are identical to each other too.

a. Assuming dwarves and elves to be concurrent processes, and using P and V operations, devise an algorithm for each type of process.
b. Is your solution correct?
c. Discuss possibly what you could do to improve your solution.
Computers and Technology
1 answer:
dsp733 years ago
7 0

Answer:

See explaination

Explanation:

function DWARVES()

{

num(dwarves) = num(dwarves)+1;

while (num(dwarves)!=5) ;

P(Ground)

Critical Section code;

V(Ground)

num(dwarves) = 0;

}

Function ELVES()

{

num(Elves) = num(Elves) + 1;

if(num(Elves) ! =5);

P(Ground)

Critical section code;

V(Ground)

num(Elves) = 0

}

Algo Explained -

We have two functions in this algo. First one is for Dwarves and second one is for elves. When any Dwarve execute it goes to its function increment number of dwarves and wait in a loop created by while loop untill number of dwarves become equal to 5 . If number of dwarf become equal to 5 it tries to enter into critical section of code . P(ground) means obtainig lock on ground . and V(Ground) means releasing that lock. If dwarves are using the grond means they are executing the critical section then untill they execute the critical section no Elves should execute critical section. For that binary semaphores or mutexes has been used . Similarly function Elves is implemented

ii) This algorithm should work fine. But If we get a situation like when dwarves are executing the critical section and got preempted before releasing the locks then there may arise a condition of starvation for Elves . Starvation is a case of longer waiting deadlock is a case of infinite waiting.

iii) So to improve our code we can add some timer so that after that each of dwarves or Elves should release the ground .

You might be interested in
Given the following code, what will be the value of finalAmount when it is displayed? public class Order { private int orderNum;
kkurt [141]

Answer:

522

Explanation:

5 0
3 years ago
How to make your nest learning thermostat stop doing something
k0ka [10]

Answer:

You could unplug it? LOL

and get a different thermostat.

Explanation:

Could you mark this answer as brainiest?

Thanks! :)

4 0
3 years ago
In unreal engines which class should be used to define the rules of the game
mel-nik [20]

Answer: The number of players and spectators present, as well as the maximum number of players and spectators allowed.

Explanation: players

8 0
3 years ago
When the national economy goes from bad to better, market research shows changes in the sales at various types of restaurants. P
zhannawk [14.2K]

Answer: it will be greater by $2.6 billion

Explanation:

7 0
3 years ago
Why is it helpful hat the ribbon tabs can collapse
UkoKoshka [18]
This is helpful in order to have a larger space to work in.

Being able to collapse the ribbon gives the user a larger document to work with instead of focusing on what they’re typing as well as extra effects.

Hope this helps!
4 0
2 years ago
Other questions:
  • Given positive integer numInsects, write a while loop that prints that number doubled without reaching 200. Follow each number w
    8·1 answer
  • c++ design a class named myinteger which models integers. interesting properties of the value can be determined. include these m
    14·1 answer
  • People with healthy media diets:
    12·1 answer
  • Which one of the following is an example of hacktivism according to you and why?
    11·1 answer
  • Select the strategies below that are likely to increase audience attention.
    14·2 answers
  • Henry must choose which type of smart speaker to use in his home. He asked you to help him decide which one will best suit his n
    11·1 answer
  • (BRAINLIEST QUESTION) What are some challenges that will need to be overcome in order for the Internet of Vehicles to become a r
    13·1 answer
  • You have been using the same computer for several years. To extend its service life, you decide to upgrade the processor. You ch
    13·1 answer
  • Which type of film would typically require the least amount of input from a screenwriter?
    10·1 answer
  • It connects computers in different cities and different countries
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!