Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You will implement this assignment in jBACI. Create a new CM source code file named concurrency.cm and submit it here. It should contain: A set
You will implement this assignment in jBACI.
Create a new CM source code file named concurrency.cm and submit it here. It should contain:
- A set of global variables:
- Semaphores named full, empty and mutex
- Constant integers SIZE with value 5 and MAX with value 20
- Integers named produced and consumed, both initialized to 0
- An integer array of length size, named buffer
- A parameterless, void function producer that:
- Loops for MAX times
- Produces a (notional) item
- Outputs to the screen the produced item number
- Locks/waits on the semaphores as appropriate (you need to figure out how this works)
- Adds the item to the buffer
- Unlocks the semaphores as appropriate
- Loops for MAX times
- A parameterless, void function consumer that:
- Loops for MAX times
- Locks/waits on the semaphores as appropriate
- Removes an item from the buffer
- Unlocks the semaphores as appropriate
- Consumes a (notional) item from the buffer
- Outputs to the screen the consumed item number
- Locks/waits on the semaphores as appropriate
- Loops for MAX times
- An appropriately-declared function main that:
- Calls initialsem to initialize the semaphores:
- full to SIZE
- mutex to 1
- empty to 0
- Contains the cobegin block to call the producer and consumer functions
- Calls initialsem to initialize the semaphores:
Notional example output should look something like the following:
Item 1 produced Item 2 produced Item 1 consumed Item 3 produced Item 4 produced Item 2 consumed Item 5 produced Item 3 consumed Item 6 produced Item 4 consumed Item 7 produced Item 5 consumed Item 8 produced Item 9 produced Item 6 consumed Item 10 produced Item 7 consumed Item 11 produced Item 8 consumed Item 12 produced Item 9 consumed Item 13 produced Item 10 consumed Item 14 produced Item 11 consumed Item 15 produced Item 16 produced Item 12 consumed Item 17 produced Item 13 consumed Item 18 produced Item 14 consumed Item 19 produced Item 15 consumed Item 20 produced Item 16 consumed Item 17 consumed Item 18 consumed Item 19 consumed Item 20 consumed
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