Reference no: EM132376264
Programming Assignment : Written Exercises
Please answer the following questions and submit them with your assignment in code-reading.txt.
Code reading
To implement synchronization primitives, you will have to understand the operation of the threading system in OS/161. It may also help you to look at the provided implementation of semaphores.
When you are writing solution code for the synchronization problems it will help if you also understand exactly what the OS/161 scheduler does when it dispatches among threads. Place the answers to the following questions in code-reading.txt.
Thread Questions
1. What happens to a thread when it exits (i.e., calls thread_exit())? What about when it sleeps?
2. What function(s) handle(s) a context switch?
3. What does it mean for a thread to be in each of the possible thread states?
4. What does it mean to turn interrupts off? How is this accomplished? Why is it important to turn off interrupts in the thread subsystem code?
5. What happens when a thread wakes up another thread? How does a sleeping thread get to run again?
Scheduler Questions
6. What function is responsible for choosing the next thread to run?
7. How does that function pick the next thread?
8. What role does the hardware timer play in scheduling? What hardware independent function is called on a timer interrupt?
Synchronization Questions
9. Describe how thread_sleep() and thread_wakeup() are used to implement semaphores. What is the purpose of the argument passed to thread_sleep()?
10. Why does the lock API in OS/161 provide lock_do_i_hold(), but not lock_get_holder()?
Synchronization Problem: Traffic Management at Podunk
You must solve this problem using the locks that you implemented above. Other solutions are not acceptable.
Traffic through the main intersection in the town of Podunk, KS has increased over the past few years. Until now the intersection has been a four-way stop but now the impending gridlock has forced the residents of Podunk to admit that they need a more efficient way for traffic to pass through the intersection.
Your job is to design and implement a solution using the synchronization primitives (locks) that you have developed in the previous part.
Modeling the intersection
Before you begin coding, answer the follow questions in exercises.txt:
1. Assume that the residents of Podunk are exceptional and follow the old (and widely ignored) convention that whoever arrives at the intersection first proceeds first. Using the language of synchronization primitives describe the way this intersection is controlled. In what ways is this method suboptimal?
2. Now, assume that the residents of Podunk are like most people and do not follow the convention described above. In what one instance can this four-way-stop intersection produce a deadlock? (It will be helpful to think of this in terms of the model we are using instead of trying to visualize an actual intersection).
Attachment:- Programming Assignment.rar