OS assignment5

2
100252365 Assignment 5 Haoming Sun Chapter 4 #10 No. Opening each website with a new thread means that if one webpage crashed, the whole browser process is crashed. Where as opening every website with a new process will give the benefit that even if one website crashes, the browser can remain working. #14 I will create 1 thread each for the input and the output. Creating more threads won’t help because all of them will be waiting on the IO to finish before resuming to a running state. I will create 4 threads for the CPU-intensive portion so that the threads can run simultaneously on 4 cores, increasing the throughput and decreasing the processing time. #15 after “pid = fork();” there will be 2 processes P0,P1. after the second “fork();” there will be P0,P1,P2 after “thread_create(…);”, there will be P0,P1,P2T0,P2T1[two threads for P2] after the last “fork();” there will be P0,P3,P1,P4,P2T0,P2T1,P5 Therefore there will be 6 unique processes and 7 unique threads. Chapter 5 #7 Race condition is possible to happen when two process are trying to access the same set of data simultaneously. For example when a course offered at some college is taught by 2 profs, and both found they mis-calculated marks for a student and tries to change the mark simultaneously. Say prof1 tries to add 10marks and prof2 tries to subtract 20 marks. Then if the original mark is 80 and prof1 hit save first, the total becomes 90. but then prof 2 hit save, and the mark becomes 60. But in reality it should have been 70. #8 1.Mutual exclusion- this is accomplished by the use of “turn”. Both processes may have a true flag value but the process that gets to go to critical section is the process specified by “turn”.

description

Personal solutions

Transcript of OS assignment5

Page 1: OS assignment5

100252365 Assignment 5 Haoming Sun Chapter 4 #10 No. Opening each website with a new thread means that if one webpage crashed, the whole browser process is crashed. Where as opening every website with a new process will give the benefit that even if one website crashes, the browser can remain working.

#14 I will create 1 thread each for the input and the output. Creating more threads won’t help because all of them will be waiting on the IO to finish before resuming to a running state. I will create 4 threads for the CPU-intensive portion so that the threads can run simultaneously on 4 cores, increasing the throughput and decreasing the processing time.

#15 after “pid = fork();” there will be 2 processes P0,P1. after the second “fork();” there will be P0,P1,P2 after “thread_create(…);”, there will be P0,P1,P2T0,P2T1[two threads for P2] after the last “fork();” there will be P0,P3,P1,P4,P2T0,P2T1,P5 Therefore there will be 6 unique processes and 7 unique threads.

Chapter 5 #7 Race condition is possible to happen when two process are trying to access the same set of data simultaneously. For example when a course offered at some college is taught by 2 profs, and both found they mis-calculated marks for a student and tries to change the mark simultaneously. Say prof1 tries to add 10marks and prof2 tries to subtract 20 marks. Then if the original mark is 80 and prof1 hit save first, the total becomes 90. but then prof 2 hit save, and the mark becomes 60. But in reality it should have been 70.

#8 1.Mutual exclusion- this is accomplished by the use of “turn”. Both processes may have a true flag value but the process that gets to go to critical section is the process specified by “turn”.

Page 2: OS assignment5

2.Progress-This is accomplished with the variables flag and turn. Since before each process exit the critical section it sets the “turn” variable to the other process we know that there will be a process in the critical section or wanting to run in CS. 3.Bounded Waiting - this is ensured by the variable turn. since each process can only modify the turn variable for the other processes that wants to enter critical section, and the waiting process clears its flag before waiting so there’s no way that one process repeatedly entering letting the other process wait indefinitely.

#9 1.Mutual exclusion- process can go to critical section if and only if the “flag” is set to in_cs. 2.Progress- if there is more than 1 process who has “flag” set to in_cs, they realize there are competing processes, so then we enter the next iteration of the outer loop which reset “flag” to want_in, and the process with index closest to turn will enter. 3.Bounded Waiting- when a process x enters critical section, its flag is not idle anymore. All processes with index number between turn and x which desire to go into critical section will eventually go in and turn will eventually become x, and eventually x gets to enter critical section.

#10 If a user level process is permitted to disable interrupts, then that means it is also able to turn off all kinds of hardware interrupts, even the “time out” interrupt, which then means the process will have infinite processor time and other processes will never have a chance to execute.