Question: write in C language: Output: Main program: When beginning execution, print a message Main thread beginning. For each producer thread created, print a message Creating
write in C language:
Output:
Main program:
When beginning execution, print a message "Main thread beginning".
For each producer thread created, print a message "Creating producer thread with id x where x
is the thread id The thread id is returned when you create a thread.
For each consumer thread created, print a message "Creating consumer thread with id x where x
is the thread id
Before the call to sleep, print "Main thread sleeping for x seconds" where x is the runtime
variable from the command line.
Before the main thread exits, print "Main thread exiting".
Producer threads:
Each time a producer thread sleeps, print a message "Producer thread x sleeping for y seconds"
where x is the thread id and y is the number of seconds.
Each time a producer thread inserts an item, print a message" "Producer thread x inserted value
y where x is the thread id and y is the random value product.
Consumer threads:
Each time a consumer thread sleeps, print a message "Consumer thread x sleeping for y seconds"
where x is the thread id and y is the number of seconds.
Each time a consumer thread removes an item, print a message" "Consumer thread x removed
value y where x is the thread id and y is the random value product.
Insert function:
Each time insertitem inserts an item, print "Insertitem inserted item x at position y where x is
the item value and y is the index into the buffer. Then print the contents of the buffer as shown
here. Print empty if the buffer entry is empty or the number stored in the entry. Lastly print
the value of in and out. Remember that the indices start at
Ex
Insertitem inserted item at position
emptyempty in out
Remove function:
Each time removeitem removes an item, print "Removeitem removed item x at position y
where x is the item value and y is the index into the buffer. Then print the contents of the buffer
and the values for in and out.
Ex
Removeitem removed item at position
emptyemptyempty in out
All this output should help you debug your program.
You will then run your program, first with only producer and consumer, and then with
different numbers of producers and consumers and hand in the output.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
