Project 3 - SEM_UNDO - Emergency rollback of binary semaphore if process holding it crashes * Tested: SEM_UNDO works on acad & CATS. Assume it works on all machines. Verdict: Use it. > If any issues with semaphores, change SEM_UNDO to 0 and if that fixes it, POST!!!!!!!! select() - permits handling multiple inlets to a program, e.g. waiting for data on both stdin and from a socket - The prototype of select() is: int select(int nfds, fd_set *readset, fd_set *writeset, fd_set errorset, timeval *timeout ) * ndfs tells select() the highest file descriptor value will be considered * readset, writeset, and errorset are bit maps (binary words) in which each bit represents a particular file descriptor. * timeout tells select() whether to block and wait and if waiting is required timeout explicitly specifies how long To attain concurrency with incoming data from user & socket, best way is to read incoming data from the socket in a child process and route it to the parent via a pipe. if(FD_ISSET(ReadEnd, &fdvar)) { // From user Input from user } if(FD_ISSET(UserRead, &fdvar)) { // From pipe or directly from the socket Packet from server } ============================================================================ Conditional Critical Regions - region X when do * Allows entry to the following code if the condition is true. * The region X is guaranteed to be mutually exclusive, i.e. only one waiting process may access X and test the condition * If there isn't a 'when' part, then a process gaining mutex to X enters immediately. ============================================================================ Monitors - Separate entity that guarantees mututal exclusion within * Only one process may be active within a monitor at any one time. > Many processes may be blocked. - Condition variables * Two member operations, wai & signal (no parents) * A process that issues a wait suspends until signaled * signal wakens the next process waiting on the same condition > If no process is waiting it has no effect. ============================================================================ Deadlock - Deadlock can arise if four conditions hold simultaneously: * Mutual Exclusion: only one process at a time can use a resource. * Hold and Wait: a process holding at least one resource is waiting to acquire additional resources held by other processes. * No Preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task. * Circular Wait: there exists a set {P0, P1, …, Pn} of waiting processes such that: P0 is waiting for a resource held by P1 P1 is waiting for a resource held by P2 … Pn is waiting for a resource held by P0 These conditions are necessary but may not be sufficient.