Operating Systems 1

Tutorial 2

  1. Distinguish between the terms 'concurrency', 'race condition', 'critical section' and 'mutual exclusion'.
  2. 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?
  3. One way to achieve mutual exclusion is to disable interrupts. What's wrong with this approach generally? Where might it be used?
  4. Show that the following piece of code will not protect the critical section:
  5. 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?
  6. Show how you could use a semaphore to enforce mutual exclusion within a critical section.
  7. What are the main differences between the low-level mutual exclusion primitives we have looked at, and the higher-level IPC (interprocess communication) mechanisms?
  8. If a piece of code executes a WAIT operation on a semaphore, is it necessarily blocked? Explain.
  9. Three threads are blocked, all WAITing on the same semaphore. Another thread performs a SIGNAL on the semaphore. What happens?
  10. Under what circumstances may a semaphore's counter acquire a negative value?
  11. Show code for two processes which use two binary semaphores, in which deadlock may occur.
  12. How might a message-passing system be implemented, making use of semaphores and shared memory? (Briefly!)
  13. 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.