Skip to content

Commit

Permalink
add Operating System 生产消费者问题伪代码
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzitiansky committed Feb 11, 2020
1 parent ccd3f00 commit dd5c10f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
33 changes: 32 additions & 1 deletion Operating Systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,38 @@ wait操作:执行wait操作的进程进入条件变量链末尾,唤醒紧急
<summary>生产者-消费者问题</summary>

> 问题描述:使用一个缓冲区来存放数据,只有缓冲区没有满,生产者才可以写入数据;只有缓冲区不为空,消费者才可以读出数据
</details>
>
> ```c
> // 伪代码描述
> // 定义信号量 full记录缓冲区物品数量 empty代表缓冲区空位数量 mutex为互斥量
> semaphore full = 0, empty = n, mutex = 1;
>
> // 生产者进程
> void producer(){
> do{
> P(empty);
> P(mutex);
> // 生产者进行生产
> V(mutex);
> V(full);
> }while(1);
> }
>
> void consumer(){
> do{
> P(full);
> P(mutex);
> // 消费者进行消费
> V(mutex);
> V(empty);
> }while(1);
> }
>
> ```
>
>
>
> </details>
<details>
<summary>哲学家就餐问题</summary>
Expand Down

0 comments on commit dd5c10f

Please sign in to comment.