Question
Write a program that starts two detached threads that communicate via 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 is empty
- Prompts the user for a string
- Reads it into the common buffer
until the user enters ^D (end of file). At that point the producer
can cause the entire process to terminate.
- The consumer thread must run an infinite loop that:
- Yields the CPU until the common buffer is non-empty
- Prints the buffer to the screen
- Sets the common buffer to empty
Answer