Question: Using the programming language C Write a program that creates 4 threads to process input from standard input as follows Thread 1, called the Input
Using the programming language C
Write a program that creates 4 threads to process input from standard input as follows
- Thread 1, called the Input Thread, reads in lines of characters from the standard input.
- Thread 2, called the Line Separator Thread, replaces every line separator in the input by a space.
- Thread, 3 called the Plus Sign thread, replaces every pair of plus signs, i.e., "++", by a "^".
- Thread 4, called the Output Thread, write this processed data to standard output as lines of exactly 80 characters.
Furthermore, in your program these 4 threads must communicate with each other using the Producer-Consumer approach.
INPUT:
- A line of input is
- A sequence of the allowed characters (see below) that does not include a line separator
- Followed by a line separator.
- Line separator
- The line separator is the newline character, i.e., ' '
- Note that line separator may not be the newline character on Windows or Mac, but that's irrelevant.
- Allowed characters
- Other than the line separator, the input will only consist of ASCII characters from space (decimal 32) to tilde (decimal 126). These are sometimes termed printable characters.
- Stop-processing line
- Your program must process input lines until it receives an input line that contains only the characters STOP, i.e., STOP followed immediately by the line separator.
- Examples: The following input lines must not cause the program to stop processing the input
- STOP!
- ISTOP
- stop
- Stop
- If there are any more lines in the input after the stop-processing line, the program must not process them.
- The input will not contain any empty lines, i.e., lines that only have space characters or no characters except the line separator.
- An input line will never be longer than 1000 characters (including the line separator).
- The input for the program will never have more than 49 lines before the stop-processing line.
- Program does not need to check the input for correctness.
OUTPUT:
- The 80 character line to be written to standard output is defined as 80 non-line separator characters plus a line separator.
- Your program must not wait to produce the output only when the stop-processing line is received.
- Whenever your program has sufficient data for an output line, the output line must be produced.
- After the program receives the stop-processing line and before it terminates, the program must produce all 80 character lines it can still produce based on the input lines which were received before the stop-processing line and which have not yet been processed to produce output.
- No part of the stop-processing line must be written to the output.
- In addition, your program must not output any user prompts, debugging information, status messages, etc.
- Your program must output only lines with 80 characters (with a line separator after each line).
- For the second replacement requirement, pairs of plus signs must be replaced as they are seen.
- Examples:
- The string abc+++def contains only one pair of plus signs and must be converted to the string "abc^+def".
- The string abc++++def contains two pairs of plus signs and must be converted to the string "abc^^def".
- Thus, whenever the Plus Sign thread replaces a pair of plus signs by a caret, the number of characters produced by the Plus Sign thread decreases by one compared to the number characters consumed by this thread.
- Examples:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
