Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a console-based application that spawns two threads: a producer and a con

ID: 3627524 • Letter: C

Question

Create a console-based application that spawns two threads: a producer and a consumer. Use any programming language.

The producer should open an input file and repeatedly copy values to a circular buffer.
The consumer should open an output file and repeatedly copy values from the same circular buffer to the file.
For both the producer and consumer, a random number of bytes between 1 and n, inclusive, should be copied each iteration, where n is specified by the user. The number of bytes should be randomized each iteration.

If the producer is unable to write to the buffer (because it does not contain enough empty elements), or if the consumer is unable to read from the buffer (because it does not contain enough unread items), then it should proceed to the next iteration, choosing a new random number of bytes to copy. (Exception: Once the producer has already read the entire file, then the consumer does not have to continue generating random numbers until it gets an exact hit; instead, it should write the rest of the buffer to complete the copy.)

When the program completes, the output file should be an exact copy of the input file.The syntax of the program should be as follows:

copyfile input output n m

where:

copyfile- is the name of your executable
input- is the name of the input file
output- is the name of the output file
n- is the maximum number of bytes to copy in any given iteration (described above)
m- is the size of the circular buffer, in bytes

Explanation / Answer

static void ThreadFunction ( object obj ) { Data data = obj as Data; ProcessThread pt = GetProcessThread( ); if( pt != null ) { Console.WriteLine( "Got PT!" ); pt.IdealProcessor = (data.Index % 2); pt.ProcessorAffinity = (IntPtr)3; pt.PriorityLevel = ThreadPriorityLevel.AboveNormal; } Signals[0].WaitOne( ); double start = pt.TotalProcessorTime.TotalSeconds; int count = COUNT / NUM_THREADS; data.Str = new string [count]; data.Doubles = new double [count]; data.Dictionary = new Dictionary [count]; for( int s = 0; s
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote