> For the complete documentation index, see [llms.txt](https://1790865014.gitbook.io/ucore-step-by-step/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://1790865014.gitbook.io/ucore-step-by-step/intro-10/7_lab7.md).

# lab7

本实验主要需要阅读代码和回答问题。

1. `kern/sync/sem.c`的信号量实现中，出现了这样的暂时禁用中断的代码：

   ```c
   static __noinline uint32_t __down(semaphore_t *sem, uint32_t wait_state) {
       bool intr_flag;
       local_intr_save(intr_flag);
       /*some code*/
       local_intr_restore(intr_flag);
   ```

   我们其实从正确的框架里删除了两句`local_intr_restore(intr_flag)`和一句`local_intr_save(intr_flag);`，请你找出是哪里删掉了，并举出删掉之后不能正常工作的一种情况。(**4分**，每找出一处1分，举出不能正常工作的情况1分)

   * 注：现在还没删这几处。
   * 同学们其实可以轻松地找到正确框架的代码，然后通过对比得到哪里是删掉的。这是否对自己分析的同学不太公平？（这个分析的过程可能还比较恶心）。可行的方式是不是，我们直接告诉同学们正确框架在哪里，只要你不想自己分析我们就允许你直接diff不同文件来找bug， 如果你觉得我们的作业有意思，就自己分析哪里应该加？
2. 证明/说明为什么我们给出的信号量实现的哲学家问题不会出现死锁。不必特别严谨，但要能说服你自己/助教？。（**3分**)
3. 证明/说明为什么我们给出的条件变量实现的哲学家问题不会出现死锁。不必特别严谨，但要能说服你自己/助教？(**3分**)
4. 给出为用户态进程/线程提供信号量机制的设计方案，并比较说明给内核级提供信号量机制的异同。（**3分**)
5. 给出为用户态进程/线程提供条件变量机制的设计方案，并比较说明给内核级提供条件变量机制的异同。（**3分**）
6. 能否不基于信号量机制来完成条件变量？如果不能，请给出理由，如果能，请给出设计说明和具体实现。(**4分**)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://1790865014.gitbook.io/ucore-step-by-step/intro-10/7_lab7.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.
