操作系统的初学者，如有疏漏或错误，欢迎指正 (^ _ ^)
3.On all current computers, at least part of the interrupt handlers are written in assembly language. Why?
Generally, high-level language do not allow access to CPU hardware, which is required during the interrupt. Actions such as saving the registers and setting the stack pointer can not be expressed in high-level languages such as C, so they are performed by a small assembly-language routine. In addition, the interrupt service routine needs to be executed as quickly as possible.
16.Can a thread ever be preempted by a clock interrupt? If so, under what circumstances? If not, why not?
User-level threads cannot be preempted by the clock unless the total number of processes has been use up (although transparent interrupts may occur). Kernel-level threads can be preempted separately. In the latter case, if the thread runs too long, the clock interrupts the current process, thereby interrupting the current thread. The kernel is free to select different threads from the same process so that the next thread can run when needed.
19.In Fig. 2-15 the thread creations and messages printed by the threads are interleaved at random. Is there a way to force the order to be strictly thread 1 created, thread 1 prints message, thread 1 exits, thread 2 created, thread 2 prints message, thread 2 exists, and so on? If so, how? If not, why not?
Yes, it can be done. After each execution of pthread_create, the main program can call pthread_join and wait for the newly created thread to exit before creating the next thread.
40.Round-robin schedulers normally maintain a list of all runnable processes, with each process occurring exactly once in the list. What would happen if a process occurred twice in the list? Can you think of any reason for allowing this?
If a process occurred twice in the list, it will get two time slice per cycle. This approach can be used to provide a larger CPU share for more important processes. However, when a process is blocked, it is better to remove all entries from the list of runnable processes.
42.Explain how time quantum value and context switching time affect each other, in a round-robin scheduling algorithm.
If the context switch time is long, the time slice must be long to scale. Otherwise, context switching’s overhead can be high. If the typical CPU burst time is less than the time slice, choosing long time slices can result in an inefficient system. If the context switch is small or negligible, we can use more freedom to select slices of time.
44.Five jobs are waiting to be run. Their expected run times are 9, 6, 3, 5, and X. In what order should they be run to minimize average response time? (Your answer will depend on X.)
51.In the dining philosophers problem, let the following protocol be used: An even-numbered philosopher always picks up his left fork before picking up his right fork; an odd-numbered philosopher always picks up his right fork before picking up his left fork. Will this protocol guarantee deadlock-free operation?
Yes. There will always be at least one fork is free and at least one philosopher who can get two forks. So there’s no deadlock.
56.The readers and writers problem can be formulated in several ways with regard to which category of processes can be started when. Carefully describe three different variations of the problem, each one favoring (or not favoring) some category of processes. For each variation, specify what happens when a reader or a writer becomes ready to access the database, and what happens when a process is finished.
Variation 1: Readers have priority. No writer may start when a reader is active. When a new reader appears, it may start immediately unless a writer is currently active. When a writer finishes, if readers are waiting, they are all started, regardless of the presence of waiting writers.
Variation 2: Writers have priority. No readers may start when a writer is waiting. When the last active process finishes, a writer is started, if there is one; otherwise, all the readers (if any) are started.
Variation 3: Symmetric version. When a reader is active, new readers may start immediately. When a writer finishes, a new writer has priority, if one is waiting. In other words, once we have shared reading, we keep reading until there are no readers left. Similarly, once we have started writing, all pending writers are allowed to run.