Hardware Reference
In-Depth Information
working for two different ticket agents, might each inadvertently sell the last seat on
some flight. Devise a synchronization method using semaphores that makes sure that
only one process at a time accesses each file (assuming the processes obey the rules).
30. To make it possible to implement semaphores on a computer with multiple CPUs that
share a common memory, computer architects often provide a Test and Set Lock in-
struction. TSL X tests the location X. If the contents are zero, they are set to 1 in a sin-
gle, indivisible memory cycle, and the next instruction is skipped. If it is nonzero, the
TSL acts like a no-op. Using TSL it is possible to write procedures lock and unlock with
the following properties. lock ( x ) checks to see if x is locked. If not, it locks x and re-
turns control. If x is already locked, it just waits until it becomes unlocked, then it
locks x and returns control. unlock releases an existing lock. If all processes lock the
semaphore table before using it, only one process at a time can fiddle with the vari-
ables and pointers, thus preventing races. Write lock and unlock in assembly language.
(Make any reasonable assumptions you need.)
31. Show the values of in and out for a circular buffer of length 65 words after each of the
following operations. Both start at 0.
a. 22 words are put in
b. 9 words are removed
c. 40 words are put in
d. 17 words are removed
e. 12 words are put in
f. 45 words are removed
g. 8 words are put in
h. 11 words are removed
32. Suppose that a version of UNIX uses 2-KB disk blocks and stores 512 disk addresses
per indirect block (single, double, and triple). What would the maximum file size be?
(Assume that file pointers are 64 bits wide).
33. Suppose that the UNIX system call
unlink(
′′
/usr/ast/bin/game3
′′
)
were executed in the context of Figure 6-37. Describe carefully what changes are
made in the directory system.
34. Imagine that you had to implement the UNIX system on an embedded system where
main memory was in short supply. After a considerable amount of shoehorning, it still
did not quite fit, so you picked a system call at random to sacrifice for the general
good. You picked pipe , which creates the pipes used to send byte streams from one
process to another. Is it still possible to implement I/O redirection somehow? What
about pipelines? Discuss the problems and possible solutions.
35. The Committee for Fairness to File Descriptors is organizing a protest against the
UNIX system because whenever the latter returns a file descriptor, it always returns the
lowest number not currently in use. Consequently, higher-numbered file descriptors
are hardly ever used. Their plan is to return the lowest number not yet used by the pro-
gram rather than the lowest number currently not in use. They claim that it is trivial to
implement, will not affect existing programs, and is fairer. What do you think?
Search WWH ::




Custom Search