Need help only with Number 3 In the state diagram for proces
Need help only with Number 3.
In the state diagram for processes, two edges are missing: there is no edge from Ready to Waiting, and there is no edge from Waiting to Running. Why? Consider the following program: int count = 0; void twiddledee(){int ¡=0; for (i=0;¡Solution
The fork() methods creates the thread and places the thread in the Ready state. Since there are 2 threads in the program, Both the threads will be created and will be put into the Ready state for the execution. It all depends upon the thread scheduler which thread to execute first. The programmer do not have control over it. Hence it could be possible that thread(A) could be executed first.
Now considering the scenario of the serial execution of the threads which are declared in the main program.
1) Thread twiddledee executes first, in this case the thread will be put on to the Running state and respective method will be called.
Hence after the loop execution, the transfer of the control will be with the ALU for computing the result of arithmetic logic.
2) It could be possible that when the ALU comes into the picture, thread twiddledee gets into Ready state from Running, and wecond thread starts executing.
Since there is only one CPU core, the task will be executed independently, i.e first thread coems into the execution will complete its task and then the second thread will complete the execution.
Case I:- If twiddledee executes first.
Value of the count variable will be 2 after the complete execution.
Thread will come to dead state after the execution.
After that twiddledum executes, which makes the value of the count variable to zero in the first operation itself.
Hence the it has not completed its task, it will be in the Running state.
Case II : If twiddledum executes first.
In this case the value of the count variable will be -4 after execution of twiddledum, and hence its value will never be 0.
