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
mojhsa [17]
3 years ago
10

Here are the codes for producer and consumer problems.

Computers and Technology
1 answer:
melomori [17]3 years ago
3 0

Answer:

If a switch happens during counter++ or counter--, we will get a wrong value for the counter.

Explanation:

counter++ counter--

register1 = counter register2 = counter

register1 = register1 + 1 register2 = register2 - 1

counter = register1 counter = register2

Lets consider this example, lets assume that counter=4, this simply means that there are 4 items which are produced already. Lets look at the following steps and value of counter after each step.

a) Producer process is updating counter++, this takes place at machine level, also, during that when it completed register1=counter counter=4

b) Supposing we have a context switch happen to consumer process and it is trying to update counter--, this takes place at machine level, also when it completed

register2=counter counter=4

register2=register2-1

counter=register2 counter=3

c) Lets assume that context switch happened back to producer process and it continues from where it stopped, look at step a

register1=register1+1

counter=register1 counter=5

This will make the value of counter variable to become 5. Consumption of one item is not reflected in the counter variable. To avoid this we need to allow the atomic execution of all these instructions. This implies completion of any updates on the counter, while others wait for its completion.

d) In the event a producer executes all these machine level instructions at once,then there is no inconsistency on this.

You might be interested in
What feature of the new internet browser, microsoft edge, allows you to write or draw on a web page, highlight items, erase your
hodyreva [135]
Web Note. You can access the feature by selecting "Make a web note" and several options on the toolbar will pop up for use. Microsoft has a help page here: https://support.microsoft.com/en-us/help/17221/windows-10-write-on-the-web
6 0
3 years ago
Does scope frequently changes during a project?<br>​
lesya [120]

Answer:

no

Explanation:

6 0
3 years ago
Read 2 more answers
When the degree of color contrast between items is low, the content is easier to see and read. True or False
Alexus [3.1K]

the answer is false

hope that helps

3 0
3 years ago
Which of the following statements correctly describe a computer program?
Naddik [55]

Answer: A. It’s a robust way to find information

Explanation:

Hope this help.

3 0
3 years ago
Read 2 more answers
Which statement, if any, about Boolean is false?
Vladimir79 [104]

Answer:

A.

Explanation:

7 0
3 years ago
Other questions:
  • Write a loop to print 10 to 90 inclusive (this means it should include both the 10 and 90), 10 per line.​
    6·1 answer
  • Data cannot be sorted or filterd accuratly if there are ________.
    12·1 answer
  • If we are using an 4-character password that contains only lowercase English alphabetic characters (26 different characters), ho
    15·2 answers
  • What is the first thing you should do when troubleshooting a computer problem
    5·2 answers
  • Describe how asymmetric encryption is used to send a message from User A to User B that assures data confidentiality, authentica
    9·1 answer
  • Which element appears within the top margin of the document but does not form the part of the body of the text?
    15·1 answer
  • What is application launchers functions​
    15·1 answer
  • Conceptos importantes de red de computadoras
    11·1 answer
  • How to delete Brainly account ?​
    12·1 answer
  • Operands may be any of the following: (select all that apply) Group of answer choices constant or constant expression register n
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!