I am trying to create a program that has two threads (producer and consumer) manipulating the same object (an integer). There will be two loops running, the first has the producer write a number (it goes 1,2,3,4) and the consumer then reads it and totals it. The second loop I need to do must have the producer write A,B,C,D and then have the consumer read it, and I'm having trouble creating a loops similar to this
for ( int count = 1; count <= 4; count++ )
But instead of 1,2,3,4 have it use A,B,C,D. Does anyone have an idea of how to accomplish that? This is what I have so far, the code is a bit jumbled but please bare with me. Thanks!
// In-Exercise 2: Synchronized2.cs
// (1) Extend the Synchronized example by adding a SharedString class.
// (2) Pass a SharedString object to Consumer and Producer constructor method calls.
// (3) Consumer object writes "A", "B", "C" and "D" into a SharedMsg object.
// (4) Producer object reads "A", "B", "C" and "D" in order from the SharedMsg object.
using
//
namespace
{
DisplayState(
}
buffer = v;
bufferFull =
sharedLocation = shared;
randomSleepTime = random;
sharedLocation.SetBuffer( count );
sum += sharedLocation.GetBuffer();
holdInteger.DisplayState(
producerThread.Name =
consumerThread.Name =
producerThread.Start();
consumerThread.Start();