https://pages.cs.wisc.edu/~remzi/OSTEP/threads-cv.pdfOurfirstquestionfocusesonmain-two-cvs-while.c(thework- ing solution). First, study the code. Do you think you have an un- derstanding of what...

1 answer below »

https://pages.cs.wisc.edu/~remzi/OSTEP/threads-cv.pdf











  1. Ourfirstquestionfocuseson
    main-two-cvs-while.c
    (thework- ing solution). First, study the code. Do you think you have an un- derstanding of what should happen when you run the program?





  2. Run with one producer and one consumer, and have the producer produce a few values. Start with a buffer (size 1), and then increase it. How does the behavior of the code change with larger buffers? (or does it?) What would you predict
    num full
    to be with different buffer sizes (e.g.,
    -m 10
    ) and different numbers of produced items (e.g.,
    -l 100
    ), when you change the consumer sleep string from default (no sleep) to
    -C 0,0,0,0,0,0,1
    ?





  3. Ifpossible,runthecodeondifferentsystems(e.g.,aMacandLinux). Do you see different behavior across these systems?











Answered Same DayNov 17, 2022

Answer To: https://pages.cs.wisc.edu/~remzi/OSTEP/threads-cv.pdfOurfirstquestionfocusesonmain-two-cvs-while.c(t...

Vikas answered on Nov 17 2022
48 Votes
Assignment
1. Our first question focuses on main-two-cvs-while.c (the working solution). First, study the code. Do you think you understan
d what should happen when you run the program?
Ans: This is the program that has two threads named as “producer” and “consumer” that uses a shared buffer (shared memory) and the producer produces something and then the consumer consumes that. We use the multi-threading to ensure that the producer never produces whenever the buffer is full & the consumer never consumes whenever the buffer is empty.
This is because if the producer produces when the buffer is full then it leads to overflow of buffer(memory) and if the consumer consumes the resource then it leads to under-flow of the memory.
Below is the output of the program that comes when we make two threads in main() called producer & consumer and run the program to see whether there is some condition of deadlock occurs or not. But it turns out that the locking mechanism is working fine and preventing the condition of deadlock.
2. Run with one producer and one consumer, and have the producer produce a few values. Start with a buffer (size 1), and then increase it. How does the behavior of the code change with larger buffers? (or does it?) What would you predict num_full to be with different buffer sizes (e.g., -m 10) and different numbers of produced items (e.g., -l 100), when you...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here