当前位置:网站首页>PV operation daily question - orange apple question (advanced version variant)
PV operation daily question - orange apple question (advanced version variant)
2022-06-10 16:10:00 【liangsena】
Orange apple problem - Higher order version variant
Yesterday's advanced version still had challenges , Let's watch a variant of it today
One 、 Problem description
There is a plate on the table , It can hold up to four fruits , Only put or take out at a time A fruit , Dad put apples on the plate , Mom put oranges on the plate ; Yes One child, one daughter , My son eats one orange at a time , My daughter eats one apple at a time . Please use semaphores and PV Operate to solve the problem .
Slightly changed :
1. The maximum number of fruits in the buffer
2. In fact, it is simpler than the advanced version , Fruit is not required to be placed alternately
Two 、 problem solving
:
// Compared with the previous topic , There is no need to set the semaphore for placing fruits alternately
semaphore mutex;
semaphore empty=4;
semaphore appleCount=0;
semaphore orangeCount=0;
Father()
{
while(1)
{
P(empty);
P(mutex);
Put in an apple ;
V(mutex);
V(appleCount);
}
}
Mother()
{
while(1)
{
P(empty);
P(mutex);
Put in an orange ;
V(mutex);
V(orangeCount);
}
}
Son()
{
while(1)
{
P(orangeCount);
P(mutex);
Take an orange ;
V(mutex);
V(empty);
}
}
Daughter()
{
while(1)
{
P(appleCount);
P(mutex);
Take an apple ;
V(mutex);
V(empty);
}
}
Do you think this problem is quite simple
3、 ... and 、 twitter
perseverance prevails ! I like the feeling that the future is unknown , You come on !
边栏推荐
- Comply with medical reform and actively layout -- insight into the development of high-value medical consumables under the background of centralized purchase 2022
- Online document collaboration tool is the first step to improve work efficiency
- 直播預告 | 解構OLAP!新型多維分析架構範式全公開!Apache Doris 將帶來五個重磅議題!
- 【第七节 函数的作用】
- Recommend an easy-to-use designer navigation website
- SQL language
- SQL语言
- Cube 技术解读 | Cube 渲染设计的前世今生
- [sans titre]
- Conversion between localdate and date
猜你喜欢

Interpretation of cube technology | past and present life of cube Rendering Design
![姿态估计之2D人体姿态估计 - Human Pose Regression with Residual Log-likelihood Estimation(RLE)[仅链接]](/img/c7/9c25da07236ef0bd241b6023e82306.gif)
姿态估计之2D人体姿态估计 - Human Pose Regression with Residual Log-likelihood Estimation(RLE)[仅链接]

RGB颜色空间、色调、饱和度、亮度、HSV颜色空间详解

Detailed explanation of RGB color space, hue, saturation, brightness and HSV color space

C # homework - student information management system

「技术干货」工业触摸屏之驱动开发及异常分析(连载)

姿态估计之2D人体姿态估计 - Distribution Aware Coordinate Representation for Human Pose Estimation【转-修改】
![[high code file format API] Shanghai daoning provides you with the file format API set Aspose, which can create, convert and operate more than 100 file formats in just a few lines of code](/img/43/086da4950da4c6423d5fc46e46b24f.png)
[high code file format API] Shanghai daoning provides you with the file format API set Aspose, which can create, convert and operate more than 100 file formats in just a few lines of code

Scope and closure

硬件仪器的使用
随机推荐
Guanghetong cooperates with China Mobile, HP, MediaTek and Intel to build 5g fully connected PC pan terminal products
2290. Minimum Obstacle Removal to Reach Corner
Software test architects, 16 pieces of advice for future generations, take a look and don't miss it
torch.nn.utils.rnn.pad_sequence()详解【Pytorch入门手册】
[untitled]
Troubleshooting of cl210openstack operation -- troubleshooting of common core problems
Jerry's long press reset and high level reset [chapter]
Google X开源抓取机械臂,无需人工标注就能一眼找到目标零件[转]
姿态估计之2D人体姿态估计 - Human Pose Regression with Residual Log-likelihood Estimation(RLE)[仅链接]
Sorting of MapReduce cases
Jerry's ble IO port interrupt and flip [chapter]
Methods commonly used in uniapp (part) - timestamp problem and rich text parsing image problem
Solution to some problems of shadow knife RPA learning and meeting Excel
MySQL8安装详细步骤
Middle office: Data middle office, business middle office, technology middle office, application middle office, AI middle office
torch. utils. data. Dataloader() details [pytoch getting started manual]
作用域和闭包
MapReduce案例之排序
硬件仪器的使用
【第14节 STL容器二】