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]
4 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:
dsp734 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
A Portable Document Format (PDF) can be opened with Adobe Acrobat Reader and many web browsers.
natka813 [3]

Answer:

True

Definition / Directions:

A PDF is a file format that provides an electronic image of text or text and graphics that looks like a printed document and can be viewed, printed, and electronically transmitted.

How to Open a PDF:

Open the Adobe Reader or any other PDF software program. Then, click the file menu near the top on the left side of the window, select Open, and browse to the location of the PDF file. Select the file you want to open by clicking the file name, and then click the Open button to open the file.

6 0
3 years ago
What is logical memory?
Eva8 [605]
Logical memory is the address space, assigned to a logical partition, that the operating system perceives as its main storage.
6 0
3 years ago
Effective note-taking helps support<br><br> action.<br> distinction.<br> distraction.<br> retention.
zloy xaker [14]
It is the last one retention because writing it out will cause it to stick in your brain better
7 0
3 years ago
Read 2 more answers
Which two statements describe the Functions of a modem
cupoosta [38]

Answer:

A modem is the internal or external device its function is to transfer data over communication lines

modems use two different types of data transmission

synchronous and asynchronous

The functions of modem have changed over years it was first used for telegrams and to transmit data in 1950s.

Modems were used with computers in  1977 for first time to transmit data between computers  firstly it was used for small amount of computers

As modem improves day by day and were able to transmit information fastly between two or more hosts and the internet network slowly spreads

There are four types of modems ,

1 Fax Modems which solely transfer data between fax machines

2 The traditional ISDN modem

3 the Digital Subscribers Line

4 the Cable Modem

Explanation:

3 0
3 years ago
Which of the following statements is true? A. Marking a presentation as final is stronger security than password protection. B.
Natali5045456 [20]
B is the answer to this questionn...
5 0
3 years ago
Read 2 more answers
Other questions:
  • In the Scrum board, prioritizing the issue backlog is done in the ———- mode.
    7·1 answer
  • References are usally innocuous because they are the least personal and direct of the four reference types
    5·1 answer
  • What does a column represent in a chart?
    13·1 answer
  • When a packet with the code is transmitted, it is received and processed by every machine on the network. this mode of operation
    12·1 answer
  • Implement the following logic in C++, Use appropriate data types. Data types are represented as either numeric (num) or string.
    5·1 answer
  • Match the expenses to their respective categories.
    6·2 answers
  • [5]Suppose a 1,600 kg car is traveling at 20.0 m/s. What average force is needed to stop the car in 4.0 s?
    8·2 answers
  • Create a relational database table in Microsoft Excel for the grocery store of 20 employers.
    12·1 answer
  • 13. WHICH OF THE FOLLOWING IS INVOLVED IN CREATING A DOCUMENT? *
    7·1 answer
  • When a number gets assigned to a variable that already has a value __________. the new number overwrites the previous value at t
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!