



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




This exam has 7 pages (including this one); make sure you have them all. Put your name on each page before starting the exam. Write your answers directly on the exam sheets, using the back of the page as necessary. Bring your exam to the front when you are finished. Please be as quiet as possible. If you have a question, raise your hand and I will come to you. However, to minimize interruptions, you may only do this once for the entire exam. Therefore, wait until you are sure you don’t have any more questions before raising your hand. Errors on the exam will be posted on the board as they are discovered. If you feel an exam question assumes something that is not written, write it down on your exam sheet. Barring some unforeseen error on the exam, however, you shouldn’t need to do this at all, so be careful when making assumptions. Use good test-taking strategy: read through the whole exam first, and answer the questions easiest for you first.
Answer: A linear address is a physical address, while a logical address is a user-space address. The latter will be translated to a physical address via the segmentation hardware.
Answer: The entryAddr is the address of the first instruction execute when the process starts running. It is a logical address. When creating a process, the stack is set up so that when the process is switched to, it will start running at that address. It must be a logical address because it will be used while the process is running, and thus must be legal for that process’s logical memory.
Answer: The memory field is a linear address that refers to the memory allocated by the kernel to store the code, data, stack, etc. for the process. It is linear for two reasons. First, we need it to perform address translation for system calls (as when implementing Copy To User). Second, we need it to be able to free the process’s memory when it terminates, by giving it back to the kernel allocator with Free.
Answer: These routines are used to copy buffers of memory from the kernel address space to the user address space and vice versa, as part of system calls. System calls that pass pointers to buffers (like PrintString) will refer to logical addresses, and these must be translated to linear addresses to access them within the kernel. Conversely, buffers in user space into which the kernel must copy its results must be similarly translated.
Answer: Only one process should be in its critical section at any given time.
Answer: A process should not be prevented from entering its critical section if no other processes are in theirs.
Answer: Once a process has started to wait to enter the critical section, it should be able to get in eventually.
Answer: Define a semaphore mutex initalized to 1. When a process wishes to enter its critical section, it does: wait(&mutex); // CS here signal(&mutex); Since the mutex is initialized to 1 , the first process to wait on it will be able to enter the critical section, but subsequent processes will block, satisfying mutual exclusion. When a process exiting the critical section signals the mutex, it unblocks a process on the semaphore, which is then allowed to enter, satisfying progress. Finally, since processes on the semaphore’s blocked queue are serviced first-come-first-serve, the waiting time is bounded.
Answer: One possibility is the ready queue (s runQueue), since it could be accessed and possibly modified by multiple threads simultaneously, it requires synchronization. GeekOS disables interrupts to prevent CPU preemption while accessing the queue.
while (1) { wait(chopstick[i]); wait(chopstick[(i+1) % n]); ... eat ... signal(chopstick[i]); signal(chopstick[(i+1) % n]); ... think ... }
Answer:
P
CS
P
P
CS
CS
Answer: Two possible answers. (a) Hold and Wait. The problem is that a philosopher can be holding one chopstick while it is waiting for another. Without this condition, we wouldn’t be able to have an edge going into and out of any process pi; edges would either go in or go out, and thus prevent a cycle. (b) Circular Waiting. Avoiding circular waiting would prevent the cycle, since resources would have to be acquired in order. No process could acquire a resource earlier in the order if it holds one later in the order.
(over)
struct User_Context { /* We need one LDT entry each for user code and data segments. */ #define NUM_USER_LDT_ENTRIES 2
/*
/* The memory space used by the process. / char memory; ulong_t size;
/* Selector for the LDT’s descriptor in the GDT */ ushort_t ldtSelector;
/*
/* Code entry point */ ulong_t entryAddr;
/* Address of argument block in user memory */ ulong_t argBlockAddr;
/* Initial stack pointer */ ulong_t stackPointerAddr; };
Figure 1: User Context structure in GeekOS