# 哲学家就餐问题

[**哲学家就餐问题**](https://zh.wikipedia.org/wiki/%E5%93%B2%E5%AD%A6%E5%AE%B6%E5%B0%B1%E9%A4%90%E9%97%AE%E9%A2%98)（英语：Dining philosophers problem）是在[计算机科学](https://zh.wikipedia.org/wiki/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6)中的一个经典问题，用来演示在[并发计算](https://zh.wikipedia.org/wiki/Concurrent_computing)中[多线程](https://zh.wikipedia.org/wiki/%E5%A4%9A%E7%BA%BF%E7%A8%8B)[同步](https://zh.wikipedia.org/wiki/%E5%90%8C%E6%AD%A5)（Synchronization）时产生的问题。

在1971年，著名的计算机科学家[艾兹格·迪科斯彻](https://zh.wikipedia.org/wiki/%E8%89%BE%E5%85%B9%E6%A0%BC%C2%B7%E8%BF%AA%E7%A7%91%E6%96%AF%E5%BD%BB)提出了一个同步问题，即假设有五台计算机都试图访问五份共享的磁带驱动器。稍后，这个问题被[托尼·霍尔](https://zh.wikipedia.org/wiki/%E6%89%98%E5%B0%BC%C2%B7%E9%9C%8D%E7%88%BE)重新表述为哲学家就餐问题。这个问题可以用来解释[死锁](https://zh.wikipedia.org/wiki/%E6%AD%BB%E7%B5%90)和资源耗尽。

![哲学家就餐问题图解](https://3199409858-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MAI8Cm8kGzoD8n-Glx1%2F-MAIT_7YBlRNIMjFT4Sq%2F-MAITbtlINs9Gt5sbGlF%2Fimage.png?alt=media\&token=614c13c7-6020-4a2d-a18b-a8ce1a0e8318)

拓展阅读 - 死锁的四个条件:

* **禁止抢占**（no preemption）：系统资源不能被强制从一个进程中退出。
* **持有和等待**（hold and wait）：一个进程可以在等待时持有系统资源。
* **互斥**（mutual exclusion）：资源只能同时分配给一个行程，无法多个行程共享。
* **循环等待**（circular waiting）：一系列进程互相持有其他进程所需要的资源。

死锁只有在四个条件同时满足时发生，预防死锁必须至少破坏其中一项。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://qingnansun.gitbook.io/problems/dining-philosophers-problem.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
