Given the following pseudo code, assume that there is no other application runni
ID: 3730731 • Letter: G
Question
Given the following pseudo code, assume that there is no other application running in the system. The system has only one CPU and the code starts execution on time 10:00 AM. We also assume that each statement’s execution time can be ignored. Assume that the Sleep function used in the code is a blocking system call. What is the print out if the code is executed on an OS with many-to-one multithreading model? What if the OS using one-to-one multithreading model? Explain your answer.
int x=0;
func(){
x+=20;
Sleep(1 hour);
Print current time;
}
void main(){
CreateThread(func);
Sleep(1 hour);
Print current time;
}
Explanation / Answer
Many-to-one model:
- In this model multiple user threads are mapped to a single kernel level thread
- Since there is only one kernel level thread, only one task will be executing at a time
- Concurrency
One-to-one Model:
- There is one kernel level thread for each use level thread
- Multiple kernel level threads are scheduled on multiple processors, number of tasks running parallely equals number of processors in the system
- True concurrency
Now when this program is being executed following is the flow:
OS with many-to-one model:
- main()
- func(), sleep in main() on hold
- increment x
- sleep func()
- print time func(): 11AM
- sleep main()
- print time main(): 12PM
OS with one-to-one model:
Here output will be random depending on which kernel thread is getting processor time but each thread will be blocked when sleep is called. So output will have random prints of time from func() and then from main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.