Multi-thread programming deadlock (c #),
I. Concept of deadlock
If the synchronization of multiple threads is improperly designed, a deadlock may occur. A deadlock is a situation where multiple threads are waiting for the other party to release resources while sharing some resources, resulting in program stagnation.
Deadlocks can lead to program stagnation, so we must avoid deadlocks when writing multi-threaded programs. In fact, the above problem is well solved, as long as the two threads access critical resources in the same order. Set the lock timeout time. This method can also be used to avoid deadlocks.
Ii. deadlock Conditions
Mutual Exclusion condition: resources cannot be shared and can only be used by one process.
Request and retention conditions: the process that has obtained the resource can apply for a new resource again.
Non-deprivation condition: allocated resources cannot be forcibly deprived from the corresponding process.
Loop wait condition: several processes in the system form a loop. Every process in the loop is waiting for resources occupied by adjacent processes.
Ps: A newbie in the blog Park. If something is wrong, you are welcome to correct it and talk about it more.