Question: Already given answers are wrong don't copy paste it.Modify the following code to demonstrate context switching between parallel running threads. The program must fulfil the
Already given answers are wrong don't copy paste it.Modify the following code to demonstrate context switching between parallel running threads. The program must fulfil the following requirements: There should be 4 threads created using Pthreads API. While all/any the threads are running, the main() function should be waiting for the threads to finish their execution. The 1st thread should continuously print the character "1" in a loop. the 2nd thread should continuously print the character "2" in a loop. the 3rd thread should continuously print the character "3" in a loop. The 4th thread slepps for 3 seconds and then takes user input if the user wants to quit or not. key, the program should terminate. Right before termination, the main() function displays the number of 1s, 2s, and 3s printed out by each thread. Sample Output 1111111111111111111111111111111111111122222222222111111111112222222222 2222233333333333333312222222222222111111112222222221111111111111222222 22222222222222222111111111113333333333333333133333331111111111111113333333332222222222222111111111113333333322222222222111111111111333333333 3333222222222222223333333333333333331111111111111111111133333333333222 2222222223 Number of 1s = 141 Number of 2s = 121 Number of 3s = 98
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
