Homework 2

Due on 9/21/99
Problems: 3.2, 3.3, 3.7, 3.11, 3.17, 3.18

Homeworks were only accepted from teams. All homework papers should have on them:


3.2) Compare the advantages and disadvantages of user- and kernel-space implementations of threads with respect to efficiency, portability, scheduling, and synchronization.

Efficiency: User-space is more efficient and faster than kernel because it only needs to swap registers as opposed to the whole PCB.

Portability: User-space is more portable since it does not require that any kernel modifications be made.

Scheduling: Kernel-space allows for pre-emption and each thread can compete for processor cycles on an equal basis with processes. User-space threads are usually non-preemptive, but they can choose to implement their own priority scheme, whereas kernel-space threads are limited by the prioity scheme of the OS. Synchronization: Much more difficult in user-space because any synchronization must be handled by an intermediary handler, and if that handler cannot resolve the contention than it has no choice but to block all of the threads (of a particular process). Synchronization of the kernel-space threads can be implemented with the same synchronization methods as for the processes.

Note: A common mistake I noticed was that some groups thought that kernel-space threads were more efficient. This usually resolved around their definition of "efficient", which they interpreted as meaning that they were more flexible and could be easily blocked. Another very common mistake was to think that only user-space threads can use semaphores and monitors. Both types of threads can use any of the synchronization primitives.

3.3) Fork/Join can be used to implement any precedence process graph. This is not necessarily true for Cobegin/Coend. Use the precedence graph in Figure 3.4 to show that the processes cannot e implemented by Cobegin/Coend without additional mechanism or loss of concurrency.

Cobegin/Coend alone cannot be used to solve the precedence process graph in Figure 3.4 because there is no mechanism to signify that P5 cannot start until both P2 and P3 are complete in addition to signifying that P4 cannot start until P2 is done. If we removed the link from P2 to P5, or if we removed the P4 node completely, then we would be able to build a precedence graph.

3.7) Show what other useful information can be derived from matrix logical clocks besides event ordering

Matrix logical clocks are useful in seeing how recently other hosts have received updates concerning this host. This could prove useful for distributed games or simulations. It could also be used to get rid of old event data that all hosts have seen. It would also prove useful in seeing if other hosts have become stuck or frozen.

Note: Despite what the book says, matrix logical clocks cannot actually be used for garbage collecting without heavy modification.

3.11) Modify the conditional critical region solution in Figure 3.14 to solve the writer preference reader/writer problem.

3.17) The semaphore concept can be generalized to something called PV/chunk. In this synchronization method a semaphore is decremented or incremented by a positive integer constant C. That is, we have P(S,C) and V(S,C) operations on semaphore S. A process calling P(S,C) is blocked if the current semaphore value is less than C. A V(S,C) operation may wake up several processes if the newly incremented semaphore value can satisfy those processes. Show one synchronization problem that can be solved by using PV/chunk but not by using simply PV. Is it possible to implement PV/chunk by using Ada rendezvous?

Use PV/chunk when you want to get a chunk or mutually exclusive access items at once in an all or nothing fashion. Simply looping to acquire a simply PV semaphore will not be atomic. Furthermore, it could lead to deadlock. For example, imagine that there exist three print spoolers. Process A needs to use all three and already has locks on two of them when Process B comes in wishes to access two of the print spoolers. Process B acquires the lock for the last spooler, and blocks waiting for an open spooler. Process A is likewise blocked.

It is possible to use Ada rendezvous to implement PV/chunk, but it requires that we already know "n", which is the number of total available items. The complication revolves around the fact that we do not know the value of C when checking the guard statments. In other words we can't pass any arguments when we use Ada rendezvous. The solution therefore involves coding the request for a certain number of resources into the Ada entry. For example, instead of calling the Ada rendezvous function "startwrite( )" (analogous to a P function) you would have to call something like "startwrite_2( )" to indicate that you wished to read two devices at once. Then, in the select switch of the Ada structure you would decrement the number of available resources by two (if they were available), just like you would for PV/chunk.

3.18) Why is there no indirect naming category for the synchronous message passing in the taxonomy shown in Figure 3.20?

Because there is no asynchronous receive in synchronous message passing, ports and mailboxes are not applicable. Communication synchronization has been established before synchronous message passing starts. Ports and mailboxes are used for asynchronous sends to an asychronous listening port.