Sie sind auf Seite 1von 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 process can use the resource at any given instant of time. 2. Hold and Wait or Resource Holding: A process is currently holding at least one resource and requesting additional resources which are being held by other processes. 3. No Preemption: The operating system must not de-allocate resources once they have been 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 by another process, which in turn is waiting for the first process to release the resource. In general, there is a set of 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 you use 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 on one 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 to release a lock. A circular wait condition. This means that there is a cycle of threads, each of which is waiting 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 techniques for 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 prevents the 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.

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.

Das könnte Ihnen auch gefallen