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 insert_item inserts an item, print "Insert_item 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 0.)
Ex.
Insert_item inserted item 27 at position 3
[empty][5][34][27][empty] in =4, out =1
Remove function:
Each time remove_item removes an item, print "Remove_item 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.
Remove_item removed item 5 at position 1
[empty][empty][34][27][empty] in =4, out =2
All this output should help you debug your program.
You will then run your program, first with only 1 producer and 1 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!