Multi-thread programming deadlock (c #),

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.