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]
2 years ago
10

Here are the codes for producer and consumer problems.

Computers and Technology
1 answer:
melomori [17]2 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
Can anyone help my please
Makovka662 [10]

order: soil, plant seeds, water, seedling, corn plant

4 0
1 year ago
Read 2 more answers
In C++, objects instantiated on the stack must be returned to program memory through the explicit use of the delete keyword.
Lady_Fox [76]

Answer:

b. False.

Explanation:

Delete function not used to remove data stored on the stack. It is only used to free memory on the heap. The C++ is programming language used to develop operating systems.

8 0
2 years ago
Which of the following documents cannot be created using the Microsoft® Word® application?
denis23 [38]
The correct answer is C. Customer spreadsheet
7 0
3 years ago
Read 2 more answers
What is an example of fibre optic cable<br>​
Arte-miy333 [17]

Answer:

printing cable

Explanation:

is a cable used to transfer information from a computer to the printer in packages

5 0
2 years ago
What is the difference between a method and a function? In what ways are they similar? Why do you think Python makes a distincti
makvit [3.9K]

Answer:

A method in python is somewhat similarto a function, except it is associated with object/classes. Methods in python are very similar to functions except for two major differences. The method is implicitly used for an object for which it is called. The method is accessible to data that is contained within the class.

5 0
3 years ago
Other questions:
  • Whenever you are passing or another vehicle is passing you, _______ is particularly important to avoid collisions. A. Turning. B
    9·2 answers
  • Mary is troubleshooting her company's LAN network. She finds out that data segments that the client is encoding are resulting in
    9·1 answer
  • What is the purpose of a scatter plot introduction to computer applications
    6·2 answers
  • A web page typically contains ________, which contains the formatting instructions for displaying the web page.
    7·1 answer
  • Which is the correct expansion of the term Internet? 
    9·2 answers
  • What are the data types used in C programming with examples
    5·1 answer
  • In "When Is a Planet Not a Planet?" why does the author say that the outer planets are made of gas when the inner planets are ma
    5·1 answer
  • What are the three basic classes of application
    14·2 answers
  • What is GND and what color wire do we connect to GND? (this is like for circuits and stuff btw)
    7·1 answer
  • 3. Write a program to find the area of a triangle using functions. a. Write a function getData() for user to input the length an
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!