15-213 Recitation 15: Final Exam Preparation Slide notes/extension questions Author: Sol Boucher === Final Exam Details ================== Remember to register! Multiple Choice (1) =================== == - What else to threads get to themselves? ("Copies" of the registers!) - What's an example of something that would decrease external fragmentation? (Smaller sbrk() requests. But what would be bad about that? [More sbrk() requests!]) Multiple Choice (2) =================== == - Would this put the data in jeopardy? (No; incomplete or inconcsistent data could just be shared with the readers. This illustrates that serialization is not always designed solely to protect against corruption of stored data.) - What are each of those file types? Which application generates each? Multiple Choice (3) =================== == - Why? - How many times does each return in the success case? In the failure case? Notice the discrepancy, and remember it when error-checking! Multiple Choice (4) =================== == - How much does each of those addition operations jump by? (8 bytes) - What problem can you run into when scanf() returns a short count? (Some of your variables are uninitialized!) Multiple Choice (5) =================== == - In what order will the signals be delivered? (It's unspecified: SIGCHLD may occur entirely before SIGUSR1, vice versa, or *one may interrupt the other's handler*! Make sure to look over shell lab again: most people had *at least one* race condition, many related to this unspecified behavior.) - Which of these is most likely to be machine dependent? (Division by zero: the kernel will only signal you if the CPU generated an interrupt.) What's an efficient way of implementing NULL? (Unmap or change the permissions of the very first virtual page!) Multiple Choice (6) =================== == - (4096 B / 4 sets = 1024 B / 4 ways = 256 / 4 B per int = 64 ints) - Could someone give an example of locality w.r.t. virtual memory? (Demand paging works well because you only take the hit on the first access to a particular addresses, at which point nearby addresses are also mapped for free.) Multiple Choice (7) =================== == - What does each store? What's the difference between data and bss, and what problem was the latter introduced to solve? - What does it mean for a function to be reentrant? (It stores its internal state in a structure that's usually owned by the caller but opaque. Does this remind you of any popular paradigm you've seen in other courses? [It's object-oriented programming: each such structure is an instance!]) (Could use mutual exclusion around the unsafe functions, although this would require cooperation with any other functions that used the same helpers.) Multiple Choice (8) =================== == - Is this true in all cases? (No: C lets you stack-allocate arrays of sizes only known at runtime. However, why is this scary? [Need to carefully watch the size, or it makes it easy to overflow the stack.]) Multiple Choice (9) =================== == - (Remember that the kernel keeps a single information block corresponding to each open().) Multiple Choice (10) ==================== == - (But remember that races don't have to involve simultaneous code execution; rather, interleaving without any parallelism can still be racy!) Multiple Choice (11) ==================== == - How should we fix it? (Each module maintains private state in its i; therefore, it should be declared static to prevent exporting the symbol to other compilation units.) Problem 2: Floating Point ========================= - (Don't forget about the "free" leading 1 in normalized numbers!) Problem 3: Arrays ================= - (It's the minor index that's going to help us, since that's the one that's going to have to skip by more than the element size.) Problem 4: Loops ================ == - (So what is this hinting the loop body is really doing? [A sum += a[i] / 2!]) Problem 5: Stack discipline =========================== Problem 6: Cache memories ========================= - What does direct mapped mean again? Write-allocate? - How many entries per cache line? (2) Problem 7: Linking ================== - (Using the extern keyword in foo.c would've generated an error that alerted us to the problem.) Problem 8: Exceptional control flow =================================== - (Code order dictates that 2N must follow N, and the wait() requires that 2 follow 4.) Problem 9: Address translation ============================== - How many sets? (16 "total" / 2 ways = 8) Problem 10: Concurrency, races, and synchronization =================================================== == == - (Because writes are performed in the main() function, this mutex is in completely the wrong spot!)