Your application is based on the Concurrency Guided Practice code and includes modifications to that code to
Fantastic news! We've Found the answer you've been seeking!
Question:
Your application is based on the Concurrency Guided Practice code and includes modifications to that code to support the creation of multiple producers and consumers, which is more representative of a real-world scenario. Incorporate the following requirements into your application:
- For all classes provide the following
- Documentation at the top of the class file that includes
- Your name
- Date of development
- Assignment (e.g., CIS317 Performance Assessment - Concurrency - Multiple Producers & Consumers)
- Description of the class
- Documentation at the top of the class file that includes
- Creat a C# project called yourname_pa_concurrency
- Using the code from the concurrency guided practice, perform the following actions:
- BlockingBuffer class
- Modify the BlockingBuffer constructor to include an integer parameter that will represent the buffer (or collection) size
- Use the parameter value as the size when creating the BlockingCollection object
- Modify the BlockingPut and BlockingGet methods to include a name parameter, and incorporate that name into the output
- Producer and Consumer classes
- Add the following data members (private properties) to each class:
- Name (string)
- SleepTime (int)
- StartProducing (int)
- StopProducing (int)
- Modify the constructor for each class to add parameters to set these properties
- Modify the Run method in each class as follows:
- the for loop should go from StartProducing to StopProducing
- the sleep time should be SleepTime * 1000 instead of the hard-coded value
- add the Name property as a parameter to the BlockingPut or BlockingGet call
- add the Name property to the output string
- Add the following data members (private properties) to each class:
- BlockingBuffer class
- The main application must be updated to do the following
- Create the buffer with a size of 5
- Create 3 producers as follows:
- P1: start 10, stop 16, sleep 2
- P2: start 25, stop 29, sleep 3
- P3: start 30, stop 39, sleep 1
- Create 2 consumers as follows:
- C1: start 1, stop 9, sleep 3
- C2: start 1, stop 13, sleep 2
Sample Output:
Your Name, Week 5 Concurrency PA - Multiple Producers & Consumers Producer P3 writes 30 Buffer cells occupied: 1 Consumer C2 reads 30 Buffer cells occupied: 0 Producer P3 writes 31 Buffer cells occupied: 1 Producer P1 writes 10 Buffer cells occupied: 2 Producer P3 writes 32 Buffer cells occupied: 3 Producer P2 writes 25 Buffer cells occupied: 4 Producer P3 writes 33 Buffer cells occupied: 5 Consumer C1 reads 31 Buffer cells occupied: 4 Producer P3 writes 34 Buffer cells occupied: 5 Consumer C1 reads 10 Buffer cells occupied: 4 Producer P3 writes 35 Buffer cells occupied: 5 Consumer C1 reads 32 Buffer cells occupied: 4 Consumer C2 reads Buffer cells occupied: 3 Producer P1 writes 11 Buffer cells occupied: 4 Producer P3 writes 36 Buffer cells occupied: 5 Consumer C1 reads 33 Buffer cells occupied: 4 Producer P3 writes 37 Buffer cells occupied: 5 Producer P2 writes 26 Buffer cells occupied: 5 Consumer C2 reads 34 Buffer cells occupied: 5 Consumer C1 reads 35 Buffer cells occupied: 4 Producer P1 writes 12 Buffer cells occupied: 5 Consumer C2 reads 11 Buffer cells occupied: 4 Producer P3 writes 38 Buffer cells occupied: 5 Consumer C2 reads 36 Buffer cells occupied: 4 Producer P3 writes 39 Buffer cells occupied: 5 Producer P3 done producing Terminating Producer Consumer C1 reads 37 Buffer cells occupied: 4 Producer P1 writes 13 Buffer cells occupied: 5 Consumer C2 reads 26 Buffer cells occupied: 5 Producer P2 writes 27 Buffer cells occupied: 5 Consumer C2 reads 12 Buffer cells occupied: 4 Producer P1 writes 14 Buffer cells occupied: 5 Consumer C2 reads 38 Buffer cells occupied: 4 Consumer C1 reads 39 Buffer cells occupied: 3 Consumer C2 reads 13 Buffer cells occupied: 2 Consumer C1 reads 27 Buffer cells occupied: 1 Producer P1 writes 15 Buffer cells occupied: 2 Producer P2 writes 28 Buffer cells occupied: 3 Consumer C2 reads 14 Buffer cells occupied: 2 Consumer C2 reads 15 Buffer cells occupied: 1 Consumer C2 reads 28 Buffer cells occupied: 0 Producer P1 writes 16 Buffer cells occupied: 1 Producer P1 done producing Terminating Producer Consumer C1 reads 16 Buffer cells occupied: 0 Consumer C1 read values totaling 260 Terminating Consumer Producer P2 writes 29 Buffer cells occupied: 1 Producer P2 done producing Terminating Producer Consumer C2 reads 29 Buffer cells occupied: 0 Consumer C2 read values totaling 311 Terminating Consumer
Related Book For
Posted Date: