当前位置:网站首页>PV operation daily question - black and white chess question (variant)
PV operation daily question - black and white chess question (variant)
2022-06-10 16:10:00 【liangsena】
Black and white chess problem ( Variant )
One 、 Problem description
There is a box with an equal number of black and white chessmen various 100 gold , Now use the automatic sorting system to separate the black and white pieces , There are two processes in the system P1 and P2.P1 Responsible for sorting white chess pieces ,P2 Is responsible for sorting the black chess pieces , The two must be sorted alternately , Press Black first white then In sequence , And it shall not be stopped before the end of sorting . use PV Operation solves the problem .
Two 、 problem solving
semaphore flag1=1;
semaphore flag2=0;
int blackNum=100;
int whiteNum=100;
P2()
{
while(1)
{
P(flag2);
P(blackNum);
Sort a black piece ;
V(flag1); // Signal to P1
}
}
P1()
{
while(1)
{
P(flag1);
P(whiteNum);
Sort a white piece ;
V(flag2); // Signal to P2
}
}
3、 ... and 、 twitter
Not much. , Only the execution order and the number of pieces are given , Slip away ~
边栏推荐
- Many MapReduce cases seek common friends in the map stage
- 安霸CV2FS/CV22FS获得ASIL C芯片功能安全认证,超越市场同类芯片水平
- 测试用例常用方法和选择原则
- 2D human posture estimation for posture estimation - numerical coordinate progression with revolutionary neural networks (dsnt)
- Software test architects, 16 pieces of advice for future generations, take a look and don't miss it
- Code implementation of sorting and serializing cases in MapReduce
- NanoMQ Newsletter 2022-05|v0.8.0 发布,新增 WebHook 拓展接口和连接认证 API
- Guanghetong high computing power intelligent module injects intelligence into 5g c-v2x in the trillion market
- Jerry's long press reset and high level reset [chapter]
- Sword finger offer 06 Print linked list from end to end
猜你喜欢

How does the wireless communication module help the intelligent UAV build the "Internet of things in the air"?

MapReduce案例之排序

2D human pose estimation for pose estimation - simdr: is 2D Heatmap representation even necessity for human pose estimation?
![姿态估计之2D人体姿态估计 - Human Pose Regression with Residual Log-likelihood Estimation(RLE)[仅链接]](/img/c7/9c25da07236ef0bd241b6023e82306.gif)
姿态估计之2D人体姿态估计 - Human Pose Regression with Residual Log-likelihood Estimation(RLE)[仅链接]
![Google X开源抓取机械臂,无需人工标注就能一眼找到目标零件[转]](/img/69/02a3e0eeaf3049f41b118cf0c58972.jpg)
Google X开源抓取机械臂,无需人工标注就能一眼找到目标零件[转]

2290. Minimum Obstacle Removal to Reach Corner
![Jerry's ble dynamic power regulation [chapter]](/img/29/22be6dca25c4e6502f076fee73dd44.png)
Jerry's ble dynamic power regulation [chapter]

广和通携手中国移动、惠普、联发科、英特尔合作打造5G全互联PC泛终端系列产品
![Jerry's ble IO port interrupt and flip [chapter]](/img/e6/bd5bb99ba79ca8daaee844689cd57f.png)
Jerry's ble IO port interrupt and flip [chapter]

Sorting and paging
随机推荐
Missing setjarbyclass() when running MapReduce task. No class found
姿态估计之2D人体姿态估计 - Numerical Coordinate Regression with Convolutional Neural Networks(DSNT)
Click to unlock "keyword" of guanghetong 5g module
Android 13 re upgrade for intent filters security
How does the wireless communication module help the intelligent UAV build the "Internet of things in the air"?
影刀RPA学习和遇见excel部分问题解决方式
广和通高算力智能模组为万亿级市场5G C-V2X注智
C # homework - student information management system
剑指 Offer 06. 从尾到头打印链表
Analysis of different dimensions of enterprise reviewers: enterprise growth of Hunan Great Wall Science and Technology Information Co., Ltd
Comply with medical reform and actively layout -- insight into the development of high-value medical consumables under the background of centralized purchase 2022
[today in history] June 10: Apple II came out; Microsoft acquires gecad; The scientific and technological pioneer who invented the word "software engineering" was born
软件测试架构师,给后辈的16条忠告,快看看别错过
Many MapReduce cases seek common friends in the map stage
Interpretation of cube technology | past and present life of cube Rendering Design
排序与分页
sm59远程连接,如果提示没有host,则在服务器上加上host,然后重启sap_SAP刘梦
姿态估计之2D人体姿态估计 - Human Pose Regression with Residual Log-likelihood Estimation(RLE)[仅链接]
Guanghetong high computing power intelligent module injects intelligence into 5g c-v2x in the trillion market
排名前十、手续费低的期货公司有哪些?安全吗