当前位置:网站首页>PV操作每日一题-餐厅上菜问题
PV操作每日一题-餐厅上菜问题
2022-06-10 10:14:00 【liangsena】
和独木桥问题相似,后面更独木桥问题
一、问题描述
一个餐厅提供中国菜、泰国菜以及西班牙菜,顾客可以自己选择要吃哪种菜系。餐厅有如下规定:任一时刻餐厅只提供一种菜系,且按第一个进餐厅的顾客的要求进行提供,选择某菜系的最后一名顾客离开后才可以提供另一种菜系;选择当前菜系的顾客可以立即进入餐厅,餐厅允许多名顾客同时进餐,数量无限制;其他顾客必须等待自己所要的菜系被提供时,才可依次进入餐厅进餐。
请用PV操作描述上述的同步与互斥问题,并给出信号量及初值含义。
二、问题求解
//设置三个数值:1:中国菜,2:泰国菜,3:西班牙菜
int i=1,2,3;
int count_i=0; //当前餐厅内某菜系的人数
semaphore mutex=1; //餐厅互斥提供菜系
semaphore mutex_i=1;//互斥访问count变量
Costumers_i()
{
P(mutex_i);
count-i++;
if(count_i==1)
{
P(mutex);
}
V(mutex_i);
吃饭;
P(mutex_i);
count_i--;
if(count_i==0)
{
V(mutex);
}
V(mutex);
}
原本的答案很长,把每一个都列出来,觉得没有必要,只用用变量代替了。
三、碎碎念
今天太累了,就到这啦~
边栏推荐
- 数组目标值target两个整数,并返回它们的数组下标
- 组合模式例子
- Phpstorm configuration database connection
- [image feature extraction] image feature extraction based on MATLAB pulse coupled neural network (PCNN) [including Matlab source code 1868]
- [edge detection] eight direction Sobel image edge detection based on MATLAB [including Matlab source code 1865]
- 已经过去多长时间的方式显示时间
- Uncaught TypeError: Cannot read properties of undefined (reading ‘colspan‘)
- 7、 Policy mode
- 六、观察者模式
- [concurrent programming JUC] four ways to create threads
猜你喜欢
![[interesting reading] deepinf: social influence prediction with deep learning](/img/67/2a90dea2f129245c4a60a5e079340f.png)
[interesting reading] deepinf: social influence prediction with deep learning

Chengdu test equipment customization_ A preliminary introduction to the data types of C language of single chip microcomputer

MDB to DB file

安装CocoaPods最新版教程

Qchart note 1: simple linear diagram lineseries

塔米狗分享|房地产企业并购只增不减,那么上哪儿找这些项目呢?

Leetcode 2000. 反转单词前缀

Today, 19:30 | graphics special session - Gao Lin, teacher team of Institute of computing technology, Chinese Academy of Sciences

"Great freehand flower and bird painting master Mr. likuchan" blockbuster digital collection launched in the whole network

ADB log fetching
随机推荐
MAC下安装MySQL+Django详细步骤
It is very convenient to make a data analysis crosstab with one line of code
2023王道C语言训练营(线索二叉树)
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(十六)
Create swift color class
Some problems in using message queue service in thinkphp6
Delphi中的冷门知识点
MySQL - operation database
2023 Wangdao C language training camp (binary search tree - sequential search - half search)
Definition and use of the apipost environment variable
Google Earth engine (GEE) - gpwv411: data set of average administrative unit area
mdb转换为db文件
mixin-- 混入
MySQL基础
Mixer: an indispensable component of video conference recording
FinalShell的下载和使用
Requirements and business model analysis - Requirements 17- requirements management
PhpStorm配置数据库连接
Introduction to development technology of multi-target application on SAP cloud platform
Personnalisation de l'équipement d'essai de Chengdu Introduction préliminaire aux types de données du langage C du micro - ordinateur à puce unique