Answered step by step
Verified Expert Solution
Link Copied!

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
  • 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
  • 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

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

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

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

Address an envelope properly.

Answered: 1 week ago

Question

Discuss guidelines for ethical business communication.

Answered: 1 week ago