|
MQX
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Communication and Synchronization (part 3)
|
||||||||||||||||||||||||
Deadlocks and their preventionA deadlock is a state where two or more tasks are blocked because they are perpetually waiting for resources which have already been allocated to the same set of tasks. Indiscriminate use of two or more semaphores may lead to such a situation. task1: task2: These two tasks may easily deadlock. Assume that they both are at the same priority level and that round-robin scheduling is applied. Task 1 obtains S1. At that moment, and before it is able to acquire S2, its time slice expires and it is placed at the end of its priority queue. Task 2 is activated. It obtains S2 and tries to acquire S1. But S1 has already been allocated to Task 1. Task 2 blocks waiting for S1. Task 1, which has remained ready, becomes active and immediately tries to acquire S2 which has been allocated to Task 2. Thus task 1 also blocks waiting for S2. A DEADLOCK
A dependence graph has as nodes the resources (semaphores) of the processes. There is a directed edge from a semaphore Si to semaphore Sj if in any of the processes, there ais a sequence of two subsequent P operations involving these two semaphores.
Example:
If the dependence graph contains a cycle, then deadlocks are possible The graph depicted in the previous page contains a cycle indicating a possible deadlock situation for the set of tasks Task1 and Task2. To guarantee freedom from deadlocks, it suffices that cycles in the dependence graph be broken. If the required resources are ordered, and the tasks request resources according to their order (i.e. a higher order resource cannot be requested until all the required lower order resources have been obtained) then the resulting dependence graph is acyclic, and thus no deadlocks can occur. Example:
If precautions are not taken, deadlocks may happen. Detecting a deadlock on-line is rather difficult, it involves a complete search on the state space of the tasking environment. One may deem that a deadlock has occurred if a task is blocked for a "long" period of time. An arbitrary timeout can be used, which if exceeded, may signify a deadlock. In such a situation, it is required that the latent task releases all its resources. In certain situations, it is computationaly more efficient to obtain the required resources in any arbitrary order (e.g. if some preliminary work needs to be done that requires only part of the resources). Obviously, such an approach is prone to deadlocks. A way to avoid deadlocks (akin to timeout) is to immediately release all obtained resources upon a block. After that, one may try again to acquire the resources, hopefully with better success. To be able to release the resources, it means that the state of the task must remain consistent after their release (i.e. it either must be restorable to the state before the acquisition of the resources or the state reached is self consistent and does not require the acquisition of the next resource to accomplish that -- e.g. it does not need to update a globally shared variable). Use of resource ordering and two-way locking in computer communications problems.One class of multiprocessor architectures comprises a set of processors communicating over dedicated channels. This architecture is modeled as a graph. Different graphs signify different communication topologies. Hypercubes are popular interconnects.
The problem now becomes that of how to allocate channels to communicating nodes so as deadlocks are avoided. Various communication mechanisms may be used.
Routing Policies
Backtracking is deadlock avoiding in that it forces a timeout of 0
for blocked paths. It can utilize any available source-destination path,
and it thus diminishes delays. |
||||||||||||||||||||||||