Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the following 3 thread and a shared global variable xinitialized to 0. a)

ID: 3609254 • Letter: G

Question

Given the following 3 thread and a shared global variable xinitialized to 0.
a) do these threads always terminate ? What is the conditionfor these threads to terminate (in what order they can end)?
T1(){ T2 (){ T3(){ while (x!=3){ while (x!=3){ while(x!3){ x=1; if(x==1) x=3; if(x==2) x=3;
} } }
} } }
b) Assume the order that at which the threads enter the systemis not known, but any order is eually likely, what is theprobability of termination for each one of the following CPUscheduling policies: 1. round robin 2. shortest job first (no preemtion, equal excutiontime) 3. random (when a time quantum expires, scheduler selects athread in a random manner)
a) do these threads always terminate ? What is the conditionfor these threads to terminate (in what order they can end)?
T1(){ T2 (){ T3(){ while (x!=3){ while (x!=3){ while(x!3){ x=1; if(x==1) x=3; if(x==2) x=3;
} } }
} } }
b) Assume the order that at which the threads enter the systemis not known, but any order is eually likely, what is theprobability of termination for each one of the following CPUscheduling policies: 1. round robin 2. shortest job first (no preemtion, equal excutiontime) 3. random (when a time quantum expires, scheduler selects athread in a random manner)

Explanation / Answer

Dear,    Given, threads excecution is,    T1 ()    {       T2 ()       {          T3()          {             while(x!= 3)            {                while(x!= 3 )                {                   while(x! = 3 )                   {                         x= 1;                         if(x==1)                               x=3;                         if(x==2)                               x=3;                   }                }             }          }       }    }    Here the threee threads share a globalvariable "x" whose initial value is 0.    During execution initially the value of "x"is 0, so, it enters the loop, then its value changed to 1. Then by"if" condition the value of "x" ix assigned to 3. In the first runall the three threads are executed. Now, the value of "x" is 3. So,the process will be terminated at the thread 3.    b) Round Robin :            Inthe round robin scheduling the threads are executed in the orderT1,T2,T3,T1,T2,T3.......            Inthis scheduling the termination occurs when the condition fails,Even the condition is failed at the thread T3 in the first run,again the threads T1,T2, and T3 are executed. In this theprobability of temination is high.       Shortest job first:                    In thisscheduling first the shortest job is executed and then the complexone. Here the probability of termination is also low when comparedto round robin scheduling.       Random Scheduling:         This is tehbest scheduling process than the round robin and the shortest jobscheduling algorithms. Here a specified quantum is assigned for thethread execution. If the the quantum is expired then the threadswill be terminated. " I hope this will help you "         This is tehbest scheduling process than the round robin and the shortest jobscheduling algorithms. Here a specified quantum is assigned for thethread execution. If the the quantum is expired then the threadswill be terminated. " I hope this will help you "
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote