最近在看 concurrency in go 的时候看到了在并发的执行代码过程中,很容易产生死锁的问题,后就查了些资料做个总结

死锁产生的必要条件

  1. Mutual Exclusion

    A concurrent process holds exclusive rights to a resource at any one time.

  2. Wait For Condition

    A concurrent process must simultaneously hold a resource and be waiting for an
    additional resource.

  3. No Preemption

    A resource held by a concurrent process can only be released by that process, so
    it fulfills this condition.

  4. Circular Wait

    A concurrent process (P1) must be waiting on a chain of other concurrent pro‐
    cesses (P2), which are in turn waiting on it (P1), so it fulfills this final condition
    too.