Unit 3 Interacting processes Flashcards
What are race conditions?
(Part 2) Race conditions are when the final outcome of a process is dependent on the timing sequence of other processes.
In a circular buffer, if the data is being overwritten by a producer before it is consumed by the consumer, what problem has occurred?
(Part 2) This shows a race between the consumer and the producer processes to get to the shared memory, and the race condition has occurred.
In deadlock, a process is blocked while waiting for a resource held by another process - in the dining philosophers problem, what would be the resource?
(Part2) In the dining philosophers problem, forks are the resource.
What is the difference between deadlock and livelock?
(Part 2) In deadloock, one or more processes are not able to execute at all.
In livelock, a process is executing operations without progressing.
If a shared Boolean variable, such as busy , were used within entry and exit protocols, would both protocols require a TAS instruction?
(Part 3) The entry protocol consists of at least two instructions, checking the variable and then setting its value, so this would require a TAS instruction to work properly as an atomic action.
An exit protocol consists of resetting the value of the Boolean variable, without any need to check it first, so this does not necessarily require a TAS instruction.
In what ways can semaphores be used?
(Part 3) Semaphores can be used for:
- ensuring mutual exclusion from critical code
- controlling access to single or multiple shared resources
- synchronising cooperating processes
How can the incorrect use of semaphores lead to problems with safety and liveness?
(Part 3) Forgetting to use semWait makes it possible for a resource to become accidentally unprotected - a safety issue.
By forgetting to use semSignal it is possible for a resource to become locked indefinitely - a liveness issue.
How can achieve mutual exclusion in Java?
(Part 4) In Java, mutual exclusion can be achieved by using synchronised methods using the synchronized keyword.
Fully synchronised objects are objects for which all the methods are synchronised, this is the safest but not the most efficient strategy. For some objects, only certain operations or parts of operations need to be carried out under mutual exclusion, so the objects do not need to be fully synchronised.
What is the wait-notify mechanism designed to assist with?
(Part 4) The wait-notify mechanism provides a way to implement condition synchronisation in synchronised methods - a thread can wait on a condition if the condition is not satisfied, and threads may notify other threads if they have altered the state of the shared data.
What is the distinction between the three thread states: BLOCKED, WAITING, and TIMED_WAITING?
(Part 4) A thread ends up in the BLOCKED state if it attempts to execute a synchronised method, but the lock for the object is already held by another thread.
Both WAITING and TIMED_WAITING are states that a thread goes into as a result of the wait method, so as a result of a condition not being satisfied. A thread in the TIMED_WAITING state can be woken up as a result of either a notification or the timeslot having expired.
What is the difference between notify and notifyAll, and which of these two methods is considered safer to use?
(Part 4) With notify only one thread gets selected to receive the notification - but it cannot be known which thread it will be. With notifyAll all threads get notified.
Generally notifyAll is safer to use, because with notify if the wrong thread receives the notification, the program may end up deadlocked, as the notification cannot be passed on to other threads.
What are the four conditions for deadlock?
(Part 6) The four conditions for deadlock are:
- mutual exclusion
- hold while waiting
- no pre-emption
- a cycle of processes
Generally, how can deadlock be prevented?
(Part 6) By arranging for one of the four conditions for deadlock not to be true.