Computer Science 162 - Fall 1996 - Smith - Midterm 1

Computer Science 162 - Fall 1996 - Smith - Midterm 1 - CS...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS 162 Midterm Exam March 1996 Note that exam total is out of 70, not out of 100. Answers in italics. Your Name: Ms. Perfect Your TA: Your Section: General Information: This is a closed book examination. You have 90 minutes to answer as many questions as possible. The number in parentheses at the beginning of each question indicates the number of points given to the question; there are 70 points in all. Write all of your answers directly on this paper. Make your answers as concise as possible (you needn't cover every available nano-acre with writing). If there is something in a question that you believe is open to interpretation, then please go ahead and interpret but state your assumptions in your answer. Problem 1 : (5 points) Of the following items, circle those that are stored in the thread control block. Answer: a, c, f, g (a) CPU registers (b) page table pointer (c) stack pointer (d) ready list (e) segment table (f) thread priority (g) program counter
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Problem 2 : (10 points) Write down the sequence of context switches that would occur in Nachos if the “main” thread were to call the following code. Assume that the CPU scheduler runs threads in FIFO order, with no time- slicing and all threads having the same priority. The WillJoin flag is used to signify that the thread will be joined to by its parent. For example, “child2 => child1” would signify that child2 switches to child1. void Thread::SelfTest2() { Thread *t1 = new Thread("child 1", WillJoin); Thread *t2 = new Thread("child 2", WillJoin); t1->Fork((VoidFunctionPtr) &Thread::Yield, t1); t2->Fork((VoidFunctionPtr) &Thread::Yield, t2); t2->Join(); t1->Join(); } main -> child1 -> child2 -> child1 -> child2 -> main (If you assumed an implementation of join that V’ed the child to ask it to finish itself, then there would be an additional couple switches at the end -- we didn’t take off for this. .) Note that neither creating nor forking a thread switches to the child thread (assuming no preemptions occur)-- the parent keeps the CPU throughout, and just puts the child on the ready list. In the above example, the children don’t start running until “main” calls join. Also note that when I fork the function Yield, when Yield runs, it will first call switch, then come back from switch, then the thread finishes. A common error was to assume that once Yield called switch, it never came back. We gave some people half credit if we could deduce that you made only one of these errors.
Background image of page 2
3 Problem 3 : (10 points) For the following implementation of Thread::Join(), say whether it either (i) works, (ii) doesn’t work, or (iii) is dangerous -- that is, sometimes works and sometimes doesn’t. If the implementation does not work or is dangerous, explain why and show how to fix it so it does work. You may assume parents always call Thread::Join() on their children
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/17/2009 for the course CS 162 taught by Professor Kubiatowicz during the Spring '02 term at University of California, Berkeley.

Page1 / 12

Computer Science 162 - Fall 1996 - Smith - Midterm 1 - CS...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online