

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Operating Systems; Subject: Computer Science; University: University of San Diego; Term: Unknown 1989;
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


All problems from OS Concepts by Silberschatz, Galvin, and Gagne
4.3 A DECSYSTEM-20 computer has multiple register sets. Describe the actions of a context switch if the new context is already loaded into one of the register sets. What else must happen if the new context is in memory rather than in a register set, and all the register sets are in use?
During a context switch, all the information about the current process (P1) must be saved to that process’s PCB, and the information about the next process (P2) must be loaded. If P2’s state is already loaded into registers, then the values of P1’s registers can remain in place, but P1 needs to record which register set it was using (if it hasn’t done so already). P1’s state should be changed to Ready (assuming it got swapped out because of a scheduler interrupt). Then, P2’s address space must be swapped in. This includes restoring access to any files P2 was working with, access to it’s call stack, etc. Finally, the system simply needs to switch to using P2’s registers as the current register set and set P2’s state to running.
If P2’s registers are not already loaded in, then P1’s registers must be saved to P1’s memory (P1’s PCB) before P2’s address space replaces P1’s. Then, P2’s registers must be loaded into this register set from P2’s PCB before P2 starts running.
Note that in a context switch, the address space swap (not the register copy) is the most time consuming step (think about the difference between thread context switching and process context switching). So even though having P2’s data already loaded into registers saves some time, it does not save that much time relative to the total time of the context switch.
5.1 Provide two programming examples of multithreading that improve performance over a single- threaded solution.
Some possible answers include:
5.2 Provide two programming examples of multithreading that do not improve performance over a single-threaded solution.
Some possible answers include:
5.3 What are two differences between user-level threads and kernel-level threads? Under what circumstances is one type better than the other?
K/L threads are better than U/L threads when you will have threads that block, for example, on I/O. In these cases, the scheduler can choose another K/L to run so that the whole process doesn’t block.
U/L threads are better when there will be a lot of them created, or when they will be created and destroyed relatively quickly because there is little creation/destruction overhead. They are also better when the threads need to communicate because thread communication is simply a procedure call in U/L threads, which is faster than going through the kernel.
5.6 What resources are used when a thread is created? How do they differ from those used when a process is created?
When a thread is created, it needs its own execution state. This basically involves allocating it memory for its stack, and giving it a PC, SP, and storage for its other registers, all within the processes address space.
When a process is created, it receives an entirely new address space, which means that the system has to create a new mapping from addresses to physical memory, and it has to allocate the process a new block of physical memory. Within that address space, the system must keep track of the open files, the process’s permissions, etc. It must also allocate things that are required for each