Reasons for Deadlock

Embed Size (px)

Citation preview

  • 7/31/2019 Reasons for Deadlock

    1/2

    A deadlock situation can arise if and only if all of the following conditions hold simultaneously

    in a system

    1. Mutual Exclusion: At least one resource must be non-shareable.Only one processcan use the resource at any given instant of time.

    2.

    Hold and Wait or Resource Holding: A process is currently holding at least oneresource and requesting additional resources which are being held by other processes.

    3. NoPreemption: The operating system must not de-allocate resources once they havebeen allocated; they must be released by the holding process voluntarily.

    4. Circular Wait:A process must be waiting for a resource which is being held byanother process, which in turn is waiting for the first process to release the resource.In general, there is asetof waiting processes, P = {P1, P2, ..., PN}, such that P1 is

    waiting for a resource held by P2, P2 is waiting for a resource held by P3 and so on till

    PN is waiting for a resource held by P1.

    5. A limited number of a particular resource. In the case of a monitor in C# (what youuse when you employ the lock keyword), this limited number is one, since a monitor

    is a mutual-exclusion lock (meaning only one thread can own a monitor at a time).6. The ability to hold one resource and request another. In C#, this is akin to locking onone object and then locking on another before releasing the first lock, for example:

    lock(a)

    {

    ...

    lock(b)

    {

    ...

    }

    }

    No preemption capability. In C#, this means that one thread can't force another thread torelease a lock.

    A circular wait condition. This means that there is a cycle of threads, each of which iswaiting for the next to release a resource before it can continue.

    He goes on to explain that the way to avoid deadlocks is to avoid (or thwart) condition four.

    Joe Duffy discusses several techniquesfor avoiding and detecting deadlocks, including one

    known as lock leveling. In lock leveling, locks are assigned numerical values, and threads must

    only acquire locks that have higher numbers than locks they have already acquired. This preventsthe possibility of a cycle. It's also frequently difficult to do well in a typical software application

    today, and a failure to follow lock leveling on every lock acquisition invites deadlock.

    http://en.wikipedia.org/wiki/Mutually_exclusive_eventshttp://en.wikipedia.org/wiki/Mutually_exclusive_eventshttp://en.wikipedia.org/wiki/Preemption_%28computing%29http://en.wikipedia.org/wiki/Preemption_%28computing%29http://en.wikipedia.org/wiki/Preemption_%28computing%29http://en.wikipedia.org/wiki/Circular_referencehttp://en.wikipedia.org/wiki/Circular_referencehttp://en.wikipedia.org/wiki/Sethttp://en.wikipedia.org/wiki/Sethttp://en.wikipedia.org/wiki/Sethttp://msdn.microsoft.com/msdnmag/issues/06/04/Deadlockshttp://msdn.microsoft.com/msdnmag/issues/06/04/Deadlockshttp://msdn.microsoft.com/msdnmag/issues/06/04/Deadlockshttp://en.wikipedia.org/wiki/Sethttp://en.wikipedia.org/wiki/Circular_referencehttp://en.wikipedia.org/wiki/Preemption_%28computing%29http://en.wikipedia.org/wiki/Mutually_exclusive_events
  • 7/31/2019 Reasons for Deadlock

    2/2

    E2 pa.>>>.

    1;ignoring the "Schliefen Plan"

    2; Inablility of Generals to grasb principels of 20century warfare, ig mobility

    3;thoughtless waste and disregard of human life and resources by High command.

    4;And finally Generals of all Nations hate to be told that they are wrong or worse incompetent.