Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program example in BACI: line pc 1 0 // example of C-- semaphore usage 2 0 3 0 semaphore count; // a general semaphore 4

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
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
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:
Example for the print out of results:
Item 1 produced
Item 2 produced
Item 3 produced
Item 1 consumed
Item 4 produced
Item 2 consumed
Item 3 consumed
..
Post source code for part A and part B
image text in transcribed
1.- In this assignment you wl implement a deadlock free variant of the bounded-buffer producer/consumer using jBACI (C- -). C-- is a subset of Cthat allows you to declare semaphores and apply the operat ions 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 Download jBACI executable files, example files, and documentation from the folder JBACI on Webcourses. The folder JBACI in Webcourses tells you how to download and install jBACI on your computer The BACI support C-programming, which is a subset of C++ extended with primitives for process synchronization (Semaphores and Monitors) Program example in BACI

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions