

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!


CSE 430 OS/161 Assignment 1b Implementing and Testing Condition Variables and Locks Version 2 Wednesday April 9, 2008 In this assignment you will be implementing basic synchronization functionality that is currently missing from the OS/161 kernel – condition variables and locks. Then you will code a test program that uses this functionality and exercises your understanding of concurrency. Hard copy portions of ASST1b are due by class time on the date indicated in the class outline. The patch file must be submitted by midnight on the same date. The OS/161 Information page available via the OS/161_info link in the left frame on the class web site main page has information and links to all the necessary support information on running this project and submitting hard copy and patch file deliverables. Of particular relevance is a Word document called Hints for ASST1b. We will start this assignment by getting the kernel for it built. Building the Kernel You will be building the OS/161 kernel the same way you did in ASST1a. Before you start you should rename the OS161-1.10_asst1 directory you constructed for ASST1a so that you can refer to it and the catsem.c program you wrote in ASST1a. Then repeat the steps under Building the Kernel in ASST1a to generate a new OS161-1.10_asst1 source directory and cs161 object tree in your home directory. See OS/161 Handout #2 for what these should look like. Try test programs sy1, sy2 and sy3 (see the section on OS/161 Thread Tests later in this write-up for more information on these tests). Only sy1 should work. Programming Section For this assignment, there will be two primary requirements:
Synchronization Test Problem For ASST1b, you will implement and test the Cat & Mouse synchronization problem just as you did for catsem.c in ASST1a except that you will implement it using the locks and condition variables you added to the OS/161 source code (it is ok to use a semaphore to notify the parent thread that all children have quit though). Call this new program catlock.c. The requirements that will be graded for catlock.c are very similar to those for catsem.c in ASST1a (see Project Deliverables and Grading). A test file containing skeleton code for the catlock.c ASST1 test program can be found in the kern/asst1/ directory of the OS/161 kernel source. After you have coded a solution to it, you need to replace the skeleton file with your updated version and reconfigure and rebuild the OS/161 kernel as you did earlier when you used the skeleton files. Additional Information Getting Started With Locks Some tips for implementing the locks. Remember, a lock is a mutually exclusive resource, which means that only one process/thread can hold the lock at a time. A lock is always initialized in the unlocked state. This means that you can’t create a lock and have a thread holding it when it is created. Think about how this relates to more basic P and V (wait and signal) semaphore functionality that can be found in kern/thread/synch.c. Is there a way that you can use existing kernel functionality to implement the locks more easily? Also, when creating a lock, what should the initial values be for its data members? Additionally, there must be a way to find the owner of a lock. Think about a way that you can identify a process/thread that is holding the lock. How can you store this with the lock? How should you handle the owner when initializing, acquiring, releasing and destroying the lock? Then finally keep in mind what areas of the code are critical sections. Here is a big hint: this is actually documented in the header file kern/include/synch.h. Getting Started With Condition-Variables A condition-variable (cv) is essentially just a condition that threads or processes are waiting on. Once the condition becomes true, then the thread(s) will get awoken (see Process Coordination HO# 9 – Use of Mutexes and Condition Variables to access a Shared Resource.) So, in order to implement this, you have to think about how threads are put to sleep and then later woken up. How can you signal the sleeping threads that the condition-variable they are waiting on has become true? You will definitely want to look at: kern/include/thread.h and kern/thread/thread.c. As a hint, you may find it easier to implement a new function in the thread code to implement the waking of one thread. This will be very useful for simplifying cv_signal. You will also want to make sure to read over the commentary in kern/include/synch.h about condition-variables. Final Word of Advice If you find that you are starting to reach anywhere near a total of 50-100 lines of code in modifications to synch.c, thread.c, synch.h and thread.h, you are working too hard. The complete lock/cv functionality can be implemented in a fairly small amount of code.