Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with the coding in C-- please Deliverables 1. Submit to Websourses the developed concurrency.cm source code file Assignment requirements 1. Two producers
I need help with the coding in C-- please
Deliverables 1. Submit to Websourses the developed concurrency.cm source code file Assignment requirements 1. Two producers 2. Two consumers 3. Mutual exclusion 4. Single buffer with maximum size 10 elements 5. Maximum 30 items produced and consumed for each producer-consumer pair Tasks Activity concurrency.em 1. Create a new CM source code file named concurrency.cm 2. Declare the following global variables a. Data type semaphore named full b. Data type semaphore named empty c. Data type semaphore named mutex d. Constant integer, value 10, for the maximum size of the buffer that stores the produced items e. Integer array with the size as defined in step d. f. Constant integer, value 30, for the maximum number of produced items for each producer 3. Write function producer to do the following a. Return type void b. Parameter list receives one integer designating the producer number (i.e. producer 1, producer 2) c. Loop while the producer has not produced the maximum of 30 items i. Apply exclusive lock on semaphores (i.c. wait or p) ii. Produce the item iii. Add item to buffer iv. Output to screen the produced item v. Calculate the next position in the buffer for the next item vi. Unlock semaphores (i.e. signal or v) d. Output the total number of items produced using mutual exclusion so the output cannot be interleaved 4. Write function consumer to do the following a. Return type void b. Parameter list receives one integer designating the producer number (1.e. consumer 1, consumer 2) c. Loop while the consumer has not consumed the maximum of 30 items i. Apply exclusive lock on semaphores (i.e. wait or p) ii. Consume an item from the buffer iii. Output to screen the consumed item iv. Calculate the next position in the buffer for the next item v. Unlock semaphores (i.e. signal or v) d. Output the total number of items consumed using mutual exclusion so the output cannot be interleaved 5. Write function statement to do the following a. Output the following information i. Student name ii. Course CGS3763 iii. University UCF 6. Write function main to do the following a. Declare four integers that will represent the two producers and two consumers b. Call function initialsem to initialize each of the three semaphores i. full with integer 10; use constant versus hardcode values ii. mutex with integer of 1; this value indicates a binary semaphore iii. empty with integer of c. Call function statement d. Write the cobegin block to concurrently call functions producer and consumer for each producer and consumer 3 Test Case 1 Test Case 2 Test Case 3 Test Case 4 Test Case 5 Producer 1 should produce 30 items Producer 2 should produce 30 items Consumer 1 should consume 30 items Cosnumer 2 should consume 30 items Output should be similar to example provided Concurrency.cm Example Output Source code written by Karin Whiting CGS 3763 UCF Producer 1 produced item 1 Consumer 1 consumed item 1 from the buffer Producer 2 produced item 1 Consumer 2 consumed item 1 from the buffer Producer 2 produced item 2 Producer 1 produced item 2 Producer 2 produced item 3 Consumer 1 consumed item 2 from the buffer Consumer 2 consumed item 2 from the buffer Consumer 1 consumed item 3 from the buffer Producer 1 produced item 3 Consumer 1 consumed item 4 from the buffer Producer 1 produced item 4 Consumer 1 consumed item 5 from the buffer Producer 1 produced item 5 Producer 2 produced item 4 Consumer 1 consumed item 6 from the buffer Consumer 2 consumed item 3 from the buffer Producer 1 produced item 6 Producer 2 produced item 5 Consumer 2 consumed item 4 from the buffer Producer 1 produced item 7 Producer 2 produced item 6 Producer 1 produced item 8 Consumer 1 consumed item 7 from the buffer Producer 1 produced item 9 Consumer 2 consumed item 5 from the buffer Producer 1 produced item 10 Producer 2 produced item 7 Producer 1 produced item 11 Consumer 1 consumed item 8 from the buffer Producer 2 produced item 8 Producer 1 produced item 12 Consumer 2 consumed item 6 from the buffer Consumer 1 consumed item 9 from the buffer Consumer 2 consumed item 7 from the buffer Consumer 1 consumed item 10 from the buffer Producer 1 produced item 13 Producer 2 produced item 9 Producer 1 produced item 14 Consumer 1 consumed item 11 from the buffer Producer 2 produced item 10 Consumer 2 consumed item 8 from the buffer Producer 1 produced item 15 Consumer 1 consumed item 12 from the buffer Consumer 2 consumed item 9 from the buffer Producer 1 produced item 16 Producer 2 produced item 4 Consumer 1 consumed item 6 from the buffer Consumer 2 consumed item 3 from the buffer Producer 1 produced item 6 Producer 2 produced item 5 Consumer 2 consumed item 4 from the buffer Producer 1 produced item 7 Producer 2 produced item 6 Producer 1 produced item 8 Consumer 1 consumed item 7 from the buffer Producer 1 produced item 9 Consumer 2 consumed item 5 from the buffer Producer 1 produced item 10 Producer 2 produced item 7 Producer 1 produced item 11 Consumer 1 consumed item 8 from the buffer Producer 2 produced item 8 Producer 1 produced item 12 Consumer 2 consumed item 6 from the buffer Consumer 1 consumed item 9 from the buffer Consumer 2 consumed item 7 from the buffer Consumer 1 consumed item 10 from the buffer Producer 1 produced item 13 Producer 2 produced item 9 Producer 1 produced item 14 Consumer 1 consumed item 11 from the buffer Producer 2 produced item 10 Consumer 2 consumed item 8 from the buffer Producer 1 produced item 15 Consumer 1 consumed item 12 from the buffer Consumer 2 consumed item 9 from the buffer Producer 1 produced item 16 Consumer 2 consumed item 10 from the buffer Producer 2 produced item 11 Producer 1 produced item 17 Consumer 1 consumed item 13 from the buffer Producer 2 produced item 12 Producer 1 produced item 18 Consumer 2 consumed item 11 from the buffer Consumer 1 consumed item 14 from the buffer Producer 2 produced item 13 Consumer 1 consumed item 15 from the buffer Producer 1 produced item 19 Consumer 1 consumed item 16 from the buffer Producer 2 produced item 14 Consumer 2 consumed item 12 from the buffer Producer 1 produced item 20 Consumer 1 consumed item 17 from the buffer Producer 2 produced item 15 Consumer 2 consumed item 13 from the buffer Producer 1 produced item 21 Consumer 1 consumed item 18 from the buffer Producer 2 produced item 16 Consumer 2 consumed item 14 from the buffer Producer 1 produced item 22 Consumer 1 consumed item 19 from the buffer Producer 2 produced item 17 Consumer 1 consumed item 20 from the buffer Producer 1 produced item 23 Producer 2 produced item 18 Consumer 1 consumed item 21 from the buffer Consumer 2 consumed item 15 from the buffer Consumer 1 consumed item 22 from the buffer Producer 1 produced item 24 Consumer 2 consumed item 16 from the buffer Producer 2 produced item 29 Consumer 2 consumed item 29 from the buffer Producer 2 produced item 30 6 Producer 2 produced 30 items Consumer 2 consumed item 30 from the buffer Consumer 2 consumed 30 items Deliverables 1. Submit to Websourses the developed concurrency.cm source code file Assignment requirements 1. Two producers 2. Two consumers 3. Mutual exclusion 4. Single buffer with maximum size 10 elements 5. Maximum 30 items produced and consumed for each producer-consumer pair Tasks Activity concurrency.em 1. Create a new CM source code file named concurrency.cm 2. Declare the following global variables a. Data type semaphore named full b. Data type semaphore named empty c. Data type semaphore named mutex d. Constant integer, value 10, for the maximum size of the buffer that stores the produced items e. Integer array with the size as defined in step d. f. Constant integer, value 30, for the maximum number of produced items for each producer 3. Write function producer to do the following a. Return type void b. Parameter list receives one integer designating the producer number (i.e. producer 1, producer 2) c. Loop while the producer has not produced the maximum of 30 items i. Apply exclusive lock on semaphores (i.c. wait or p) ii. Produce the item iii. Add item to buffer iv. Output to screen the produced item v. Calculate the next position in the buffer for the next item vi. Unlock semaphores (i.e. signal or v) d. Output the total number of items produced using mutual exclusion so the output cannot be interleaved 4. Write function consumer to do the following a. Return type void b. Parameter list receives one integer designating the producer number (1.e. consumer 1, consumer 2) c. Loop while the consumer has not consumed the maximum of 30 items i. Apply exclusive lock on semaphores (i.e. wait or p) ii. Consume an item from the buffer iii. Output to screen the consumed item iv. Calculate the next position in the buffer for the next item v. Unlock semaphores (i.e. signal or v) d. Output the total number of items consumed using mutual exclusion so the output cannot be interleaved 5. Write function statement to do the following a. Output the following information i. Student name ii. Course CGS3763 iii. University UCF 6. Write function main to do the following a. Declare four integers that will represent the two producers and two consumers b. Call function initialsem to initialize each of the three semaphores i. full with integer 10; use constant versus hardcode values ii. mutex with integer of 1; this value indicates a binary semaphore iii. empty with integer of c. Call function statement d. Write the cobegin block to concurrently call functions producer and consumer for each producer and consumer 3 Test Case 1 Test Case 2 Test Case 3 Test Case 4 Test Case 5 Producer 1 should produce 30 items Producer 2 should produce 30 items Consumer 1 should consume 30 items Cosnumer 2 should consume 30 items Output should be similar to example provided Concurrency.cm Example Output Source code written by Karin Whiting CGS 3763 UCF Producer 1 produced item 1 Consumer 1 consumed item 1 from the buffer Producer 2 produced item 1 Consumer 2 consumed item 1 from the buffer Producer 2 produced item 2 Producer 1 produced item 2 Producer 2 produced item 3 Consumer 1 consumed item 2 from the buffer Consumer 2 consumed item 2 from the buffer Consumer 1 consumed item 3 from the buffer Producer 1 produced item 3 Consumer 1 consumed item 4 from the buffer Producer 1 produced item 4 Consumer 1 consumed item 5 from the buffer Producer 1 produced item 5 Producer 2 produced item 4 Consumer 1 consumed item 6 from the buffer Consumer 2 consumed item 3 from the buffer Producer 1 produced item 6 Producer 2 produced item 5 Consumer 2 consumed item 4 from the buffer Producer 1 produced item 7 Producer 2 produced item 6 Producer 1 produced item 8 Consumer 1 consumed item 7 from the buffer Producer 1 produced item 9 Consumer 2 consumed item 5 from the buffer Producer 1 produced item 10 Producer 2 produced item 7 Producer 1 produced item 11 Consumer 1 consumed item 8 from the buffer Producer 2 produced item 8 Producer 1 produced item 12 Consumer 2 consumed item 6 from the buffer Consumer 1 consumed item 9 from the buffer Consumer 2 consumed item 7 from the buffer Consumer 1 consumed item 10 from the buffer Producer 1 produced item 13 Producer 2 produced item 9 Producer 1 produced item 14 Consumer 1 consumed item 11 from the buffer Producer 2 produced item 10 Consumer 2 consumed item 8 from the buffer Producer 1 produced item 15 Consumer 1 consumed item 12 from the buffer Consumer 2 consumed item 9 from the buffer Producer 1 produced item 16 Producer 2 produced item 4 Consumer 1 consumed item 6 from the buffer Consumer 2 consumed item 3 from the buffer Producer 1 produced item 6 Producer 2 produced item 5 Consumer 2 consumed item 4 from the buffer Producer 1 produced item 7 Producer 2 produced item 6 Producer 1 produced item 8 Consumer 1 consumed item 7 from the buffer Producer 1 produced item 9 Consumer 2 consumed item 5 from the buffer Producer 1 produced item 10 Producer 2 produced item 7 Producer 1 produced item 11 Consumer 1 consumed item 8 from the buffer Producer 2 produced item 8 Producer 1 produced item 12 Consumer 2 consumed item 6 from the buffer Consumer 1 consumed item 9 from the buffer Consumer 2 consumed item 7 from the buffer Consumer 1 consumed item 10 from the buffer Producer 1 produced item 13 Producer 2 produced item 9 Producer 1 produced item 14 Consumer 1 consumed item 11 from the buffer Producer 2 produced item 10 Consumer 2 consumed item 8 from the buffer Producer 1 produced item 15 Consumer 1 consumed item 12 from the buffer Consumer 2 consumed item 9 from the buffer Producer 1 produced item 16 Consumer 2 consumed item 10 from the buffer Producer 2 produced item 11 Producer 1 produced item 17 Consumer 1 consumed item 13 from the buffer Producer 2 produced item 12 Producer 1 produced item 18 Consumer 2 consumed item 11 from the buffer Consumer 1 consumed item 14 from the buffer Producer 2 produced item 13 Consumer 1 consumed item 15 from the buffer Producer 1 produced item 19 Consumer 1 consumed item 16 from the buffer Producer 2 produced item 14 Consumer 2 consumed item 12 from the buffer Producer 1 produced item 20 Consumer 1 consumed item 17 from the buffer Producer 2 produced item 15 Consumer 2 consumed item 13 from the buffer Producer 1 produced item 21 Consumer 1 consumed item 18 from the buffer Producer 2 produced item 16 Consumer 2 consumed item 14 from the buffer Producer 1 produced item 22 Consumer 1 consumed item 19 from the buffer Producer 2 produced item 17 Consumer 1 consumed item 20 from the buffer Producer 1 produced item 23 Producer 2 produced item 18 Consumer 1 consumed item 21 from the buffer Consumer 2 consumed item 15 from the buffer Consumer 1 consumed item 22 from the buffer Producer 1 produced item 24 Consumer 2 consumed item 16 from the buffer Producer 2 produced item 29 Consumer 2 consumed item 29 from the buffer Producer 2 produced item 30 6 Producer 2 produced 30 items Consumer 2 consumed item 30 from the buffer Consumer 2 consumed 30 itemsStep 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