Question: Write a code in with JBACi in C-- that reads the following: concurrency.cm Create a new CM source code file named concurrency.cm Declare the following

Write a code in with JBACi in C-- that reads the following:

concurrency.cm

  1. Create a new CM source code file named concurrency.cm
  1. Declare the following global variables
    1. Data type semaphore named full
    2. Data type semaphore named empty
    3. Data type semaphore named mutex
    4. Constant integer, value 10, for the maximum size of the buffer that stores the produced items
    5. Integer array with the size as defined in step d.
    6. Constant integer, value 30, for the maximum number of produced items for each producer
  1. Write function producer to do the following
    1. Return type void
    2. Parameter list receives one integer designating the producer number (i.e. producer 1, producer 2)
    3. Loop while the producer has not produced the maximum of 30 items
      1. Apply exclusive lock on semaphores (i.e. wait or p)
      2. Produce the item
      3. Add item to buffer
      4. Output to screen the produced item
      5. Calculate the next position in the buffer for the next item
      6. Unlock semaphores (i.e. signal or v)
    4. Output the total number of items produced using mutual exclusion so the output cannot be interleaved
  1. Write function consumer to do the following
    1. Return type void
    2. Parameter list receives one integer designating the producer number (i.e. consumer 1, consumer 2)
    3. Loop while the consumer has not consumed the maximum of 30 items
      1. Apply exclusive lock on semaphores (i.e. wait or p)
      2. Consume an item from the buffer
      3. Output to screen the consumed item
      4. Calculate the next position in the buffer for the next item
      5. Unlock semaphores (i.e. signal or v)
    4. Output the total number of items consumed using mutual exclusion so the output cannot be interleaved
  1. Write function statement to do the following
    1. Output the following information
      1. Student name
      2. Course CGS3763
      3. University UCF
  1. Write function main to do the following
    1. Declare four integers that will represent the two producers and two consumers
    2. Call function initialsem to initialize each of the three semaphores
      1. full with integer 10; use constant versus hardcode values
      2. mutex with integer of 1; this value indicates a binary semaphore
      3. empty with integer of 0
    3. Call function statement
    4. Write the cobegin block to concurrently call functions producer and consumer for each producer and consumer

Test Case 1

Producer 1 should produce 30 items

Test Case 2

Producer 2 should produce 30 items

Test Case 3

Consumer 1 should consume 30 items

Test Case 4

Cosnumer 2 should consume 30 items

Test Case 5

Output should be similar to example provided

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!