当前位置:网站首页>PV operation daily question 1 - single wooden bridge problem (variant 1)
PV operation daily question 1 - single wooden bridge problem (variant 1)
2022-06-10 16:10:00 【liangsena】
Variant 1 of the single wooden bridge problem
One 、 Problem description
The car passes the single wooden bridge in the east-west direction , To ensure safety , As long as there is no car on the bridge , Then one side's car is allowed to cross the bridge , When all the cars of the other side have passed , The other side's car is allowed to cross the bridge , There can be at most K A car passed .
Two 、 problem solving
:
int eastCount=0; // The current number of cars on the bridge from the East
int westCount=0; // The current number of cars on the bridge from the West
semaphore bridge=1; // The cars on both sides are mutually exclusive
semaphore eastMutex=1; // Exclusive access eastCount
semaphore westMutex=1; // Exclusive access westCount
semaphore maxNum=k; // The maximum number of cars on the bridge
East()
{
while(1)
{
P(eastMutex);
if(eastCount==0)
{
P(bridge);
}
eastCount++;
V(eastMutex);
P(maxNum);
Cross the bridge from the East ;
V(maxNum);
P(eastMutex);
eastCount--;
if(eastCount==0)
{
P(bridge);
}
V(eastMutex);
}
}
West()
{
while(1)
{
P(westMutex);
if(westCount==0)
{
P(bridge);
}
westCount++;
V(eastMutex);
P(maxNum);
Cross the bridge from the West ;
V(maxNum);
P(westMutex);
westCount--;
if(westCount==0)
{
P(bridge);
}
V(westMutex);
}
}
3、 ... and 、 twitter
Apply for one when crossing the bridge maxNum Resources are enough .
边栏推荐
- The fragrant locust flowers on the fragrant locust road have been in a hurry for four years.
- Aggregate sum of MapReduce cases
- SQL language
- Analysis of different dimensions of enterprise reviewers: enterprise growth of Hunan Great Wall Science and Technology Information Co., Ltd
- 服务器运维环境安全体系(下篇)
- ORB_ Slam2 visual inertial tight coupling positioning technology route and code explanation 1 - IMU flow pattern pre integration
- NanoMQ Newsletter 2022-05|v0.8.0 发布,新增 WebHook 拓展接口和连接认证 API
- 【第14节 STL容器二】
- Kubernetes binary installation (v1.20.16) (V) verifying master deployment
- This and object prototypes
猜你喜欢

点击解锁广和通5G模组“关键词”

Rk3308--8 channels changed to dual channels + recording gain

2D human posture estimation for posture estimation - numerical coordinate progression with revolutionary neural networks (dsnt)
![2D human pose estimation with residual log likelihood estimation (RLE) [link only]](/img/c7/9c25da07236ef0bd241b6023e82306.gif)
2D human pose estimation with residual log likelihood estimation (RLE) [link only]
![Google X开源抓取机械臂,无需人工标注就能一眼找到目标零件[转]](/img/69/02a3e0eeaf3049f41b118cf0c58972.jpg)
Google X开源抓取机械臂,无需人工标注就能一眼找到目标零件[转]

这几个垂直类小众导航网站,你绝对不会想错过

Comply with medical reform and actively layout -- insight into the development of high-value medical consumables under the background of centralized purchase 2022

SQL language

Application scenario introduction of nixie tube driver chip + voice chip, wt588e02b-24ss

我用 MATLAB 复刻了抖音爆火小游戏 苹果蛇
随机推荐
Save a window with a specific size, resolution, or background color
Query-Convert QuickView是灰掉的解决办法(转)_SAP刘梦
Rk3308--8 channels changed to dual channels + recording gain
2290. Minimum Obstacle Removal to Reach Corner
Live broadcast preview | deconstruct OLAP! The new multidimensional analysis architecture paradigm is fully open! Apache Doris will bring five big issues!
MapReduce案例之聚合求和
[object].
Jerry's ble OTA upgrade requires shutting down unnecessary peripherals [chapter]
I used Matlab to reproduce the trembling sonic boom Fire Games Apple snake
Smart home (3) competitive product analysis of Intelligent Interaction
uniapp中常用到的方法(部分) - 时间戳问题及富文本解析图片问题
广和通高算力智能模组为万亿级市场5G C-V2X注智
Android 13 re upgrade for intent filters security
推荐一个好用的设计师导航网址
Jerry's ble abnormal power consumption [chapter]
姿态估计之2D人体姿态估计 - Human Pose Regression with Residual Log-likelihood Estimation(RLE)[仅链接]
[untitled] audio Bluetooth voice chip, wt2605c-32n real-time recording upload technical scheme introduction
SQL语言
Apple mailbox configures QQ mailbox, 163 mailbox, edu mailbox, Gmail mailbox, and obtains Gmail calendar
Add Anaconda's bin directory to path