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
Match the ernerging technologies to their descriptions.
Talja [164]

Answer:

1

1

Explanation:

5 0
3 years ago
Write an IF statement involving a Boolean operator (AND, OR or
vova2212 [387]

Answer:

i need a friend , ...............r u up?

6 0
1 year ago
An html element that describes the content of a web page is called a(n):
Marizza181 [45]
I think its <tagname> content right here </tag name>
3 0
3 years ago
How do i write this in c++ = scnr.nextInt();<br> please help
LenaWriter [7]
Int whatever = scnr.nextInt();



Although usually when a class has a next* member function, it usually needs to check that there IS a next, that you haven't reached the end. Without knowing the class that scnr was instantiated from, I can't guess.
7 0
4 years ago
Question # 2
vagabundo [1.1K]

Answer:

Customer surveys can be used to ask specific questions.

The type of feedback gathered, depends on the phase of the project and the goals for the feedback.

Feedback can be gathered from everyday activities, like support calls.

Explanation:

6 0
3 years ago
Other questions:
  • Can anyone one help in outlook....plzzzz:)
    13·1 answer
  • Write a class that can make comparisons between the efficiency of the common methods from the List interface in the ArrayList an
    5·1 answer
  • Résumés for teenagers and young adults typically consist of<br> (Apex)
    11·2 answers
  • A business wants to centralize its administrative tasks. At the same time, it wants the existing systems to manage and sustain t
    14·2 answers
  • Interpretation is adding meaning to information by making connections and comparisons and by exploring causes and consequences.
    11·1 answer
  • What is it called when an attacker convinces you to enter personal information at an imposter website after receiving an email f
    10·2 answers
  • g The state of Massachusetts at one time had considered generating electric power by harvesting energy crops and burning them. A
    15·1 answer
  • The physical layer of the OSI model is not foundational to any of the other layers. True or False
    8·1 answer
  • Which component of the computer keeps the operating system when the computer is running​
    10·1 answer
  • What is not recyclable in a<br> hybrid car<br> hydrogen car<br> petrol car
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!