当前位置:网站首页>PV操作每日一题-橘子苹果问题(高阶版变式)
PV操作每日一题-橘子苹果问题(高阶版变式)
2022-06-10 10:14:00 【liangsena】
昨天的高阶版还是有挑战,今天一起看个它的变式好啦
一、问题描述
桌上有一个盘子,最多可以容纳四个水果,每次只能放入或者取出一个水果,爸爸专门向盘子放入苹果,妈妈专门向盘子放入橘子;有一儿一女,儿子每次拿一个橘子吃,女儿每次拿一个苹果吃。请使用信号量和PV操作求解该问题。
稍微的变了下:
1.缓冲区容纳水果数量最大值
2.其实比起高阶版简单了些,不要求交替放水果
二、问题求解
:
//相对于上一道题目,不用设置用于交替放水果的信号量了
semaphore mutex;
semaphore empty=4;
semaphore appleCount=0;
semaphore orangeCount=0;
Father()
{
while(1)
{
P(empty);
P(mutex);
放入一个苹果;
V(mutex);
V(appleCount);
}
}
Mother()
{
while(1)
{
P(empty);
P(mutex);
放入一个橘子;
V(mutex);
V(orangeCount);
}
}
Son()
{
while(1)
{
P(orangeCount);
P(mutex);
拿走一个橘子;
V(mutex);
V(empty);
}
}
Daughter()
{
while(1)
{
P(appleCount);
P(mutex);
拿走一个苹果;
V(mutex);
V(empty);
}
}
是不是感觉这道题还是蛮简单的
三、碎碎念
坚持就是胜利!就是喜欢未来是未知的这种感觉,大家加油!
边栏推荐
- MAC下安装MySQL+Django详细步骤
- 怎样简洁明了地说清楚产品需求?
- Question bank and answers of 2022 metal and nonmetal mine hoist operation examination
- 2022年普通脚手架工(建筑特殊工种)操作证考试题库及模拟考试
- MATLAB 学习笔记(3)MATLAB 矩阵的进阶操作
- 万物生长,各自高贵
- What are the tools and software needed for SCM development
- Notes to docker advanced chapter (7) steps to build a redis three master and three slave cluster case in docker
- [497. random points in non overlapping rectangles]
- fastadmin使用PHPExcel导出表格数据到Excel中
猜你喜欢

Detailed steps for installing mysql+django under mac

ADB log fetching

一行代码制作数据分析交叉表,太便捷了

"Isolation insurance" has become a "net red" product, but many policyholders say that it is difficult to settle claims
![[image feature extraction] image feature extraction based on MATLAB pulse coupled neural network (PCNN) [including Matlab source code 1868]](/img/ca/59f8390c67ceb682e43db7ff8acfd6.png)
[image feature extraction] image feature extraction based on MATLAB pulse coupled neural network (PCNN) [including Matlab source code 1868]

2023王道C语言训练营(二叉查找树-顺序查找-折半查找)

phpstrom 将项目上传码云

Selenium distributed testing

Concurrent asyncio asynchronous programming

SAP 云平台多目标应用 Multi-Target Application 的开发技术介绍
随机推荐
2022劳务员-岗位技能(劳务员)考试试题及答案
Eg2131 test circuit
8、 Chain mode
[edge detection] eight direction Sobel image edge detection based on MATLAB [including Matlab source code 1865]
九、委托模式
Composite mode example
In 2025, the output value, added value and other scale indicators of the construction industry will continue to remain at the forefront of the country
Phpstorm configuration database connection
62. 不同路径-动态规划
NFT链游GameFi系统开发,元宇宙游戏搭建
2021 ciscn-pwn 初赛
2022年金属非金属矿山提升机操作考试题库及答案
单片机开发需要的工具以及软件有哪些
Drawing curve with MATLAB
OSG basic operation
Axure add drop-down menu linkage
MATLAB 学习笔记(3)MATLAB 矩阵的进阶操作
一个独特的简历生成器,开源了!
成都自控开发_单片机程序的一般开发流程是怎样
phpstrom 将项目上传码云