| Winter 2007 Midterm Solutions |
| Problems | Grader |
|---|---|
| 1,2 | Ben |
| 3,4,6 | Forum |
| 5 | Vincenzo |
| 7 | Mendel |
There were many different ways of doing this problem. The most common solution looked something like this:
//shared variables and semaphores with initial values: semaphore T1_sema(0); //init'd to zero semaphore T2_sema(0); //init'd to zero semaphore done_sema(0); //init'd to zero
| void ComputeZ(){ StartThread(T1); StartThread(T2); sema_down(done_sema); return; } | void T1(){ y = F3(y); sema_up(T2_sema); x=F1(x); sema_down(T1_sema); z = F3(x,y); sema_up(done_sema); } | void T2(){ sema_down(T2_sema); y = F2(y); sema_up(T1_sema); } |
(Based on the solution to Problem 1 above)
| T0-S |
| T1-S |
| T1-1 |
| T2-S |
| T1-2 |
| T2-1 |
| T2-E |
| T1-E |
| T0-E |
Same as above because even with priority donation, T1 was the highest priority thread after T2. Hence T1 runs after T2 is blocked in both the cases.
1) Page tables entries of different processes can map regions of processes' virtual addresses to the same physical frames.
2) A segment table and a number of page tables (one per process segment) are associated with each process. By having two segments point to the same page table, the page table will be shared, and as a consequence also the related physical frames will be.
Yes. Each process has its own page table that maps virtual addresses to physical ones. As explained in the lecture, each entry in the page table includes protection bits (such as "read", "write") that tell the allowed operations of the process over the page. Therefore, Process 1 and Process 2 can have their page table entries (with protection bits read/write on) map the same physical frame region, while Process 3 can have its page table entries map it with only protection bit read on.
To emulate reference bits, use the invalid bit in the page table as follows: -Set page permissions to “invalid” / "not present" -On any access to the page, will get a fault - in the page fault handler, Mark as referenced
Position independent code (PIC) solves a problem with libraries that are shared across multiple processes. Rather than having to place a shared library at the same address in every process or re-link the library to use different addresses in different processes, PIC allows the system to run the same code at different addresses in different processes by building the library code to be easily relocatable, hence the name position independent code.