Docsity

OS/161 Assignment 1a: Synchronization Using Semaphores - Cat & Mouse Problem, Assignments of Operating Systems

Toggle sidebar
bg1
CSE 430 OS/161 Programming Assignment 1a (ASST1a)
Synchronization Using Semaphores
Version 6 Saturday November 1, 2008
In this assignment you will be using the basic semaphore synchronization functionality that is in
the OS/161 kernel. You will code a test program that uses this functionality and exercises your
understanding of concurrency. The entire Assignment 1 has 3 parts:
1. Implementing Synchronization Using Semaphores – ASST1a
2. Implementing and Testing Condition Variables and Locks – ASST1b
3. Additional Synchronization Problem ASST1c
This write-up is for ASST1a.
Hard copy portions of ASST1a are due on the day indicated on the course outline available on
the class web site. In particular the hard copy portions are due by class time and the patch file
must be submitted by midnight.
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.
We will start this assignment by getting the kernel for it built.
Building and Installing OS/161 Source Programs for ASST1a
You will be building the kernel in the same fashion as the previous assignment. You will need
updated versions of conf.kern, menu.c and test.h to do this. They are available in a tarball at the
same site as the OS/161 Toolchain – the link to which is given at the top the os/161_info page on
the class web site. You should use the tarball os161-1.10_asst1.tar.gz which also has the same
complete set of other kernel sources contained in the tarball used for ASST0 (os161-1.10.tar.gz)
plus any necessary skeletons needed for additional synchronization test programs and OS/161
modifications to be used in ASST1a, ASST1b and ASST1c. You need to download this into your
home directory and extract it just as you did for os161-1.10.tar.gz in ASST0. For your reference
the extraction is as follows:
cd ~
tar vzxf os161-1.10_asst1.tar.gz
This will create a new subdirectory in your home directory called os161-1.10_asst1 which will
have all the sources, configuration, menu and test files you need to build and execute a version of
OS/161 especially set up for ASST1. As with the previous assignment, all paths will be given
relative to the root of the OS/161 source path, in this case the os161-1.10_asst1 directory. To
start off, make sure you are in this directory and then:
./configure
make
Building an OS/161 Kernel for ASST1a
pf3
pf4
pf5

Partial preview of the text

Download OS/161 Assignment 1a: Synchronization Using Semaphores - Cat & Mouse Problem and more Assignments Operating Systems in PDF only on Docsity!

CSE 430 OS/161 Programming Assignment 1a (ASST1a) Synchronization Using Semaphores Version 6 Saturday November 1, 2008 In this assignment you will be using the basic semaphore synchronization functionality that is in the OS/161 kernel. You will code a test program that uses this functionality and exercises your understanding of concurrency. The entire Assignment 1 has 3 parts:

  1. Implementing Synchronization Using Semaphores – ASST1a
  2. Implementing and Testing Condition Variables and Locks – ASST1b
  3. Additional Synchronization Problem ASST1c This write-up is for ASST1a. Hard copy portions of ASST1a are due on the day indicated on the course outline available on the class web site. In particular the hard copy portions are due by class time and the patch file must be submitted by midnight. 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. We will start this assignment by getting the kernel for it built. Building and Installing OS/161 Source Programs for ASST1a You will be building the kernel in the same fashion as the previous assignment. You will need updated versions of conf.kern , menu.c and test.h to do this. They are available in a tarball at the same site as the OS/161 Toolchain – the link to which is given at the top the os/161_info page on the class web site. You should use the tarball os161-1.10_asst1.tar.gz which also has the same complete set of other kernel sources contained in the tarball used for ASST0 ( os161-1.10.tar.gz ) plus any necessary skeletons needed for additional synchronization test programs and OS/ modifications to be used in ASST1a, ASST1b and ASST1c. You need to download this into your home directory and extract it just as you did for os161-1.10.tar.gz in ASST0. For your reference the extraction is as follows: cd ~ tar vzxf os161-1.10_asst1.tar.gz This will create a new subdirectory in your home directory called os161-1.10_asst1 which will have all the sources, configuration, menu and test files you need to build and execute a version of OS/161 especially set up for ASST1. As with the previous assignment, all paths will be given relative to the root of the OS/161 source path, in this case the os161-1.10_asst1 directory. To start off, make sure you are in this directory and then: ./configure make Building an OS/161 Kernel for ASST1a

We are now ready (finally) to build an actual object OS/161 kernel, called kernel-ASST1 that will run on the System/161 emulator. From the os161-1.10_asst1 directory perform the following steps. They will be explained after doing this.

below. 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 on page 1 of this assignment. Cat & Mouse You are to use the P and V semaphores supplied with OS/161 to solve the catsem synchronization problem described below. You have cats and mice that are caged in different areas. In between these areas is a feeding area that has a certain number of feeding bowls. You need to regularly feed both the cats and the mice while preventing the mice from getting eaten. If a cat is eating at a bowl and sees a mouse, the mouse will get eaten. If a mouse is at a bowl eating, and a cat comes out, the mouse will get eaten. Cats and mice can never be at the feeding bowls at the same time. You are to write catsem with the provided specifications. Skeleton code for catsem is in kernel/asst1/catsem.c. You may start from this code or you may start from scratch. The requirements that will be graded for Cat & Mouse are:  Neither group should be allowed to starve, they both must be fed regularly  You should try to keep all bowls utilized. So, if you have 2 bowls, 2 cats or 2 mice should be eating at the same time as often as possible. You shouldn’t just act as though there is just a single bowl and only feed 1 cat or mouse at a time.  You should write the code so that it will work if the number of cats, mice, or feeding bowls is changed. Your solution should demonstrate that it works for at least two bowls, 3 cats and 3 mice and every cat and mouse eating at least twice. In addition, all eating should eventually end.  There should be at least 2 eating sessions during which both cats and mice eat (but not at the same time) and each cat and each mouse should eat exactly once during an eating session.  Each animal thread should check if it is violating the condition that cats and mice can’t see each other in the feeding area. Additional Information OS/161 Thread Tests OS/161 has thread tests that are built into the kernel. If you explored OS/161 in the previous assignment you might have come across these under the tests (?t) menu. You may also have noticed that the sy1 test succeeds and tests sy2 and sy3 fail when you attempt to run them. This is because the kernel has not implemented the locks for sy2 or the condition-variables for sy. You should examine the code for sy1 in the kernel to see examples of how P and V semaphores can be used. The function that ultimately implements the sy1 terminal command is called semtest and can be found in kern/test/synchtest.c. Due to limitations in the kernel memory manager, you may get a memory error if you try to run too many sy1 tests. Simply restart the kernel and try it again.

Project Deliverables and Grading (12 points + 2 points extra credit)

  1. (2 points) Hard copy of the catsem.c source file that you modified or added with the parts added/changed indicated by comments. Comments can be brief. Block comments can help but are not required.
  2. (3 points) A very brief design document that outlines your implementation of this assignment. It should include the following:  Description of your implementation of catsem. You should explain how your approach, insures proper cycling between cats and mice making sure that no animal starves, takes care of multiple iterations of cat and mouse eating sessions, and deallocation of resources when eating is complete. To do this, a clear explanation of what each semaphore does will suffice.  Additionally you should explain how you are testing for undesirable conditions in your code. For example, explain how you verify that a cat never actually eats a mouse or that you are making maximum utilization of the feeding bowls.
  3. (3 points) Program output during execution. The simple way to demonstrate most of these things is to add assert and kprintf statements to your synchronization program code and then use any of the methods for capturing program output listed in the OS/161 Projects Program Output Hard Copy Submission Information Page reachable from the OS/161 Information page on the class website to capture program output. As a minimum, your print statements should indicate:  Start of eating  Start and end of an eating cycle  End of eating and for each eating cycle the following or a printout with equivalent information for all cats, mice and bowls:  cat CATNUMBER beginning to eat at bowl BOWLNUMBER  cat CATNUMBER finishing eating at bowl BOWLNUMBER  mouse MOUSENUMBER beginning to eat at bowl BOWLNUMBER  mouse MOUSENUMBER finishing eating at bowl BOWLNUMBER
  4. (4 points) Electronic submission of an ASST1a patch file generated and submitted as per the description available on the OS/161 Projects Patch File Generation and Submission Information for ASST1 document reachable from the OS/161 Information page on the class website. Extra credit (2 points) Numbering cycles and printing out the cycle number at the start and end of every eating cycle (1 point) Numbering bowls and printing out the bowl number each time a cat or mouse starts and finishes eating at a bowl (1 point) As for ASST0 you are invited to:
    1. Report any bugs or problems in the assignment, the web support and the write-up.
    2. Give your thoughts on the suitability of this assignment for cse430.