Question
(Concurrency Semaphores) Due February 13th, 2019 (11:59 p.m.) 1.- In this assignment you will implement a deadlock free variant of the bounded-buffer producer/consumer using jBACI
(Concurrency Semaphores)
Due February 13th, 2019 (11:59 p.m.)
1.- In this assignment you will implement a deadlock free variant of the bounded-buffer
producer/consumer using jBACI (C - -). C- - is a subset of C + + that allows you to declare
semaphores and apply the operations P and V.
In the standard solution with one producer and one consumer, you will need at least three
semaphores named:
a) Full->to stop the producer from producing items when the buffer is full. (initial value n= buffer size)
b) Empty->to stop the consumer from consuming items from the buffer when the buffer is empty (initial value zero)
c) Mutex->to allow only one process in the critical section (initial value one)
In this homework you will implement the bounded buffer producer/consumer, there will be one producer (P), one Consumer (C) and one buffer; the size of the buffer is 5.
The producer will produce 20 items and stop running.
The consumer will consume items from the buffer until the 20 items have been consumed
Project Direction:
You will write the program based on the
BACI interpreter.
Program example in BACI:
line pc
1 0 // example of C-- semaphore usage
2 0
3 0 semaphore count; // a "general" semaphore
4 0 binarysem output; // a binary (0 or 1) semaphore for unscrambling
output
5 0
6 0 void increment()
7 0 {
8 0 p(output); // obtain exclusive access to standard output
9 2 cout << "before v(count) value of count is " << count << endl;
10 6 v(output);
11 8 v(count); // increment the semaphore
12 10 } // increment
13 11
14 11 void decrement()
15 11 {
16 11 p(output); // obtain exclusive access to standard output
17 13 cout << "before p(count) value of count is " << count << endl;
18 17 v(output);
19 19 p(count); // decrement the semaphore (or stop -- see manual text)
20 21 } // decrement
21 22
22 22 main()
23 23 {
24 23 initialsem(count,0);
25 26 initialsem(output,1);
26 29 cobegin {
27 30 decrement(); increment();
28 36 }
29 37 } // main
Test your solution
You must run and test your solution for two cases as explain below and
compare and comment on the results emitted by each test:
a) Test your first solution
b) Introduce a time delay in the consumer and test your solution.
Time delay can be implemented using a dummy loop that iterates, for example, 1000 times
Project Submission:
What to submit?
For each test you must submit the source code and the output file
showing the results
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started