OS Tutorial - Assignment 3

Outline/Agenda:

 


Semaphore Creation (semget) and initialization (semctl) are not atomic operations.

This can lead to race conditions (very very hard to debug).

Stevens has come up with a clever trick to overcome this problem. You may use his code for your semaphore creation.

Code:

http://www.kohala.com/~rstevens/

See the following link:

http://www.cim.mcgill.ca/~franco/OpSys-304 427/messages/node89.html

 


Problem:

You need to cleanup all Sys5 IPC resources when your program exits. Neglecting this will cost you marks on this assignment.

Which process does the cleanup though? If you have several processes running you can’t just cleanup the IPC resources before everyone else exits.

Solutions:

Various nasty tricks involving signals (these are bad because they interrupt otherwise blocking operations e.g hint: semaphore wait etc). You need to add a lot of error detection code etc.

Very cool trick you can use:

Watchdog process. Makes use of SEM_UNDO.

Each process in the app signals a semaphore (+1) with the SEM_UNDO flag. A watchdog is forked and waits on the semaphore to reach 0. As every child process exits, the +1 is undone… bingo your watchdog knows everyone has exited.

Hint: Your watchdog will be killed by CTRL-C unless you setsid() after forking. See man pages.

 

 


Discussion of what IPC resources are needed in the assignment.

These will be tested for in your assignments.

Hint: a great test to make sure you have no race conditions is to run the game for a long time without any delays (sleeps, etc…). Then repeat to check all the cells are in the same state after n generations.

The class notes for IPC, along with the man pages will be invaluable references for this assignment.

Suggestion:

 

 

Life3Dviewer library

See the README.Lib file for a lot of important info.

General discussion of how to use, how this should interface with your assignment etc…

Tips on extras. e.g setting viewing angles, starting/stopping rotation etc…

 

 

These notes are simply an outline of the material covered in the tutorial.