Operating Systems 1
Tutorial 2
-
Distinguish between the terms 'concurrency', 'race condition', 'critical
section' and 'mutual exclusion'.
-
Process 1 and process 2 share a single integer variable. Process 1 only
writes to the variable; process 2 only reads from the variable. Is a race
condition possible?
-
One way to achieve mutual exclusion is to disable interrupts. What's wrong
with this approach generally? Where might it be used?
-
Show that the following piece of code will not protect the critical
section:
door = OPEN;
...
enterCriticalSection:
while(door == CLOSED) /* busywait */;
door = CLOSED;
/* Perform critical task. */
leaveCriticalSection:
door = OPEN;
How could you make it work, with a little help from the hardware?
-
Show how you could use a semaphore to enforce mutual exclusion within a
critical section.
-
What are the main differences between the low-level mutual exclusion primitives
we have looked at, and the higher-level IPC (interprocess communication)
mechanisms?
-
If a piece of code executes a WAIT operation on a semaphore, is it necessarily
blocked? Explain.
-
Three threads are blocked, all WAITing on the same semaphore. Another thread
performs a SIGNAL on the semaphore. What happens?
-
Under what circumstances may a semaphore's counter acquire a negative value?
- Show code for two processes which use two binary semaphores, in which deadlock may occur.
-
How might a message-passing system be implemented, making use of semaphores
and shared memory? (Briefly!)
- How might a message-passing system be implemented, making use only of pipes? Assume that there is only one process sending messages to the port, and only one process receiving messages from the port.