当前位置:网站首页>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 .
边栏推荐
- 服务器运维环境安全体系(下篇)
- Sorting of MapReduce cases
- C # game prototype character map dual movement
- Unified certification center oauth2 certification pit
- Live broadcast preview | deconstruct OLAP! The new multidimensional analysis architecture paradigm is fully open! Apache Doris will bring five big issues!
- [MySQL basics]
- C # homework - student information management system
- 2D human posture estimation for posture estimation - simple baseline (SBL)
- 点击解锁广和通5G模组“关键词”
- Rk3308--8 channels changed to dual channels + recording gain
猜你喜欢
![姿态估计之2D人体姿态估计 - Human Pose Regression with Residual Log-likelihood Estimation(RLE)[仅链接]](/img/c7/9c25da07236ef0bd241b6023e82306.gif)
姿态估计之2D人体姿态估计 - Human Pose Regression with Residual Log-likelihood Estimation(RLE)[仅链接]

2D human pose estimation for pose estimation - simdr: is 2D Heatmap representation even necessity for human pose estimation?

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

Anti "internal roll", it is said that 360 enterprise security cloud will launch the "one click forced off duty" function, and the computer will automatically close the office software

MapReduce之Reduce阶段的join操作案例

姿态估计之2D人体姿态估计 - SimDR: Is 2D Heatmap Representation Even Necessary for Human Pose Estimation?

Live broadcast preview | deconstruct OLAP! The new multidimensional analysis architecture paradigm is fully open! Apache Doris will bring five big issues!

Many MapReduce cases seek common friends in the map stage

This and object prototypes
![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]
随机推荐
【MySQL基础】
MapReduce案例之聚合求和
Guanghetong cooperates with China Mobile, HP, MediaTek and Intel to build 5g fully connected PC pan terminal products
Jerry's long press reset and high level reset [chapter]
Baidu open source ice-ba installation and operation summary
Anti "internal roll", it is said that 360 enterprise security cloud will launch the "one click forced off duty" function, and the computer will automatically close the office software
Live broadcast preview | deconstruct OLAP! The new multidimensional analysis architecture paradigm is fully open! Apache Doris will bring five big issues!
运行mapreduce任务缺失setJarByClass()报错找不到类
sm59远程连接,如果提示没有host,则在服务器上加上host,然后重启sap_SAP刘梦
Google x open source grabbing manipulator can find the target part at a glance without manual marking [turn]
Opencv 4 handwriting recognition: perfect self built training set
Troubleshooting of cl210openstack operation -- troubleshooting of common core problems
[section 14 STL container II]
Jerry's ble OTA upgrade requires shutting down unnecessary peripherals [chapter]
LocalDate与Date相互转换
排序与分页
Click to unlock "keyword" of guanghetong 5g module
Middle office: Data middle office, business middle office, technology middle office, application middle office, AI middle office
MapReduce案例之多Map阶段求共同好友
[section 7 function]