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

Thank you all for your help. This site is full of lifesavers. Write a program th

ID: 3611396 • Letter: T

Question

Thank you all for your help. This site is full of lifesavers.

Write a program that starts two detached threads that communicatevia a global string variable.
• The main thread must
   • Set the common buffer to empty
   • Start the communicating threads
   • Exit
• The producer thread must run a loop that:
   • Yields the CPU until the common buffer isempty
   • Prompts the user for a string
   • Reads it into the common buffer
until the user enters ^D (end of file). At that point theproducer can cause the entire
process to terminate.
• The consumer thread must run an infinite loop that:
   • Yields the CPU until the common buffer isnon-empty
   • Prints the buffer to the screen
   • Sets the common buffer to empty

Explanation / Answer

#include#include #include #include #include using namespace std;string x;void *MyThread_p(void *arg){while(1){if(x==""){cout
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