(Solved) : Multithreaded Program Two Threads First Thread Displays Letter X Screen Second Thread Disp Q37159672 . . .


Below is a multithreaded program with two threads. The first thread displays the letter X on the screen and the second thread displays the letter ‘O on the screen. The threads are executed on a busy (with several active processes) computer on a time-sharing manner where the execution path of the threads is completely unpredictable #include #include #include <stdio.h> <unistd.h> <pthread.h> // repeat the times ) operation 100,000 times to slow down the // execution of the instructions #de fine RPT 100000 void print xO int i; float x; while (1) // the multiplication operation below is for consuming some CPU for (i-0 i<RPT: i+) x3.1415926 3.1415926; ) printf (“x”) //time to slow down the execution void+ print o0 int i; float x; while (1) ( // the multiplication operation below is for consuming some CPU //time to slow down the execution for (i-0; ї<RPT ; printf (“O”) ¡++) { 3.1415926+3.1415926; } x int main pthread t tidl, tid2; pthread create (&tidl, NULL,&print_x, NULL) pthread create (&tid2,NULL, &print_O, NULL) // Wait till threads complete. Not really related to this // question in this assignment. Can be ignored. pthread join(tidl, NULL) pthread join(tid2, NULL) printf “n An instance of the execution of the program produced the output below. Newlines and line numbers were added manually after the output was captured to make it more readable. Based on the information and assumption given above, please answer the following questions A. Suppose that Line 1 of the output indicates the corresponding thread completed the full duration of its allocated time slice. Has the thread completed its execution after Line 1? B. Line 2 is shorter than Line 1. What could be the reason(s)? C. What could be the possible reasons that caused the output from Line 08 to Line 15? D. Assuming the program is executed to completion, will the effective execution output of each of the 2 threads (that is the number of Xs and Os printed) be different if the process executing this program is the only active process in the computer? Why and why not? E. Is it possible to produce exactly the same output (sequence of Xs and Os) with multiple execution instances of the program? Why or why not? Is it possible to have Os printed out before Xs? Why or why not? 01: 05: 07: 08: XXX 09: o 10: x 11: O 12: X 13: O 14: x 15: 0 16: 17: 18: 19: Show transcribed image text Below is a multithreaded program with two threads. The first thread displays the letter X on the screen and the second thread displays the letter ‘O on the screen. The threads are executed on a busy (with several active processes) computer on a time-sharing manner where the execution path of the threads is completely unpredictable #include #include #include // repeat the times ) operation 100,000 times to slow down the // execution of the instructions #de fine RPT 100000 void print xO int i; float x; while (1) // the multiplication operation below is for consuming some CPU for (i-0 i
Expert Answer
Answer to Below is a multithreaded program with two threads. The first thread displays the letter X on the screen and the second t…
OR