当前位置:网站首页>PV operation daily question - ticket sales
PV operation daily question - ticket sales
2022-06-10 10:46:00 【liangsena】
Ticket sales
The classic synchronization problem of fried chicken !
One 、 Problem description
The car driver and the conductor must work together , On the one hand, the driver can only drive after the conductor closes the door , therefore , The conductor shall close the door and inform the driver to drive , Then the conductor sells tickets . On the other hand , Only when the car has stopped , The conductor can open the door to get on and off the passengers , Therefore, the driver shall inform the conductor after parking . Suppose there is a driver and two conductors on a certain bus , The car is currently stopping at the departure station to pick up passengers , Try semaphores and PV Operate to solve the problem .
The reason for the two conductors is that the bus used to have two carriages , So there are two conductors , The background of a relatively old topic ~
Two 、 problem solving
semaphore close1=0;
semaphore close2=0;
semaphore open1=0;
semaphore open2=0;
driver()
{
while(1)
{
P(close1); // The driver asked the conductor 1:“ Close the door ”
P(close2); // The driver asked the conductor 2:“ Close the door ”
Driving a car ;
Parking ;
V(open1); // The driver informed the conductor 1:“ The car stopped , You can open the door ”
V(open2); // The driver informed the conductor 2:“ The car stopped , You can open the door ”
}
}
conductor1()
{
while(1)
{
A guest - close - Sell ticket ;
V(close1); // Answer the driver :“ The door is closed , You can drive ”
The bus is running ;
P(open1); // Asked the driver :“ It stopped ”
Open door - Drop off ;
}
}
conductor2()
{
while(1)
{
A guest - close - Sell ticket ;
V(close2); // Answer the driver :“ The door is closed , You can drive ”
The bus is running ;
P(open2); // Asked the driver :“ It stopped ”
Open door - Drop off ;
}
}
That's it , See you tomorrow !
边栏推荐
- 杰理之BLE OTA 升级需要关闭不必要的外设【篇】
- 蔚来季报图解:营收99亿同比增24% 经营亏损近22亿
- Colorui color matching details
- Hardcore spoiler! With 11 topics and 14 celebrities, dragon dragon dragon community entered Intel meetup and announced the agenda!
- Question bank and answers of 2022 metal and nonmetal mine hoist operation examination
- Mixin -- mixed
- [FAQ] summary of common problems and solutions during the use of rest API interface of sports health service
- Random number letter (upper case) combination
- PV操作每日一题-缓冲区问题
- 2023 Wangdao C language training camp (binary search tree - sequential search - half search)
猜你喜欢

VS Code支持配置远程同步了

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

Vs code supports configuring remote synchronization

珈创生物冲刺创业板:年营收1.3亿 实控人曾为武大教授

山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(十七)

stm32 printf乱码

「诗经」主题文化数字藏品中奖名单公布

Yutai semiconductor rushes to the scientific innovation board: the annual revenue is 830million, and the actual controller is American

Industrial Internet Architecture

MySQL实战45讲_8_从一个问题来加深对 mysql 可重复读的理解
随机推荐
Industrial Internet Architecture
Question bank and answers of 2022 metal and nonmetal mine hoist operation examination
Sublime Text - 01 代码追踪
【先楫HPM6750测评】RT-Thread开发环境搭建和Hello World
Yutai semiconductor rushes to the scientific innovation board: the annual revenue is 830million, and the actual controller is American
最大和的连续子数组
Splishsplash架构介绍
pytorch安装教程
2023 Wangdao C language training camp (clue binary tree)
Today, 19:30 | graphics special session - Gao Lin, teacher team of Institute of computing technology, Chinese Academy of Sciences
Vite's public directory
EG2131测试电路
Detailed steps for installing mysql+django under mac
可以在网上炒股开户吗?是安全的吗?
Download and use of finalshell
fcpx插件:PremiumVFX Animation Presets(动画循环预设) v1.0.1特别版
Implementation code of several recent good papers (with source code download)
How to choose cities, schools and majors for the college entrance examination?
VS Code支持配置远程同步了
常用Shell命令 - 02 压缩和解压缩