当前位置:网站首页>PV operation daily question - single log bridge problem
PV operation daily question - single log bridge problem
2022-06-10 16:11:00 【liangsena】
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 .
It's not hard to find out , It's a reader writer problem
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
East()
{
while(1)
{
P(eastMutex);
if(eastCount==0)
{
P(bridge);
}
eastCount++;
V(eastMutex);
Cross the bridge from the East ;
P(eastMutex);
eastCount--;
if(eastCount==0)
{
P(bridge);
}
V(eastMutex);
}
}
West()
{
while(1)
{
P(westMutex);
if(westCount==0)
{
P(bridge);
}
westCount++;
V(eastMutex);
Cross the bridge from the West ;
P(westMutex);
westCount--;
if(westCount==0)
{
P(bridge);
}
V(westMutex);
}
}
3、 ... and 、 twitter
There isn't much fresh , No more than is first The car on the bridge bridge resources , The last one to get off the bridge Car release for bridge resources , visit xCount You can use mutually exclusive access .
That's it , Slip away ~
边栏推荐
- C # homework - student information management system
- 【历史上的今天】6 月 10 日:Apple II 问世;微软收购 GECAD;发明“软件工程”一词的科技先驱出生
- “绽放杯”5G应用奖项大满贯!广和通多个联合项目荣获通用产品专题赛一、二、三等奖
- uniapp中常用到的方法(部分) - 时间戳问题及富文本解析图片问题
- Scope and closure
- Jerry's ble OTA upgrade requires shutting down unnecessary peripherals [chapter]
- C # game prototype character map dual movement
- Many MapReduce cases seek common friends in the map stage
- uniapp中常用到的方法(部分) - 時間戳問題及富文本解析圖片問題
- 测试用例常用方法和选择原则
猜你喜欢

MapReduce之排序及序列化案例的代码实现

2D pose estimation for pose estimation - (openpose) realtime multi person 2D pose estimation using part affinity fields

Save a window with a specific size, resolution, or background color

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

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

智能电网终极Buff | 广和通模组贯穿“发、输、变、配、用”全环节

Troubleshooting of cl210openstack operation -- troubleshooting of common core problems

Online document collaboration tool is the first step to improve work efficiency
![姿态估计之2D人体姿态估计 - Human Pose Regression with Residual Log-likelihood Estimation(RLE)[仅链接]](/img/c7/9c25da07236ef0bd241b6023e82306.gif)
姿态估计之2D人体姿态估计 - Human Pose Regression with Residual Log-likelihood Estimation(RLE)[仅链接]

运行mapreduce任务缺失setJarByClass()报错找不到类
随机推荐
姿态估计之2D人体姿态估计 - Distribution Aware Coordinate Representation for Human Pose Estimation【转-修改】
Sorting and paging
【历史上的今天】6 月 10 日:Apple II 问世;微软收购 GECAD;发明“软件工程”一词的科技先驱出生
idea新建项目报错org.codehaus.plexus.component.repository.exception.ComponentLookupException:
Code implementation of sorting and serializing cases in MapReduce
Guanghetong high computing power intelligent module injects intelligence into 5g c-v2x in the trillion market
C # game prototype character map dual movement
[sans titre]
顺应医改,积极布局——集采背景下的高值医用耗材发展洞察2022
影刀RPA学习和遇见excel部分问题解决方式
kubernetes 二进制安装(v1.20.16)(五)验证 master 部署
The CPU load caused by implicit conversion is nearly 100%
[section 7 function]
2D human posture estimation for posture estimation - numerical coordinate progression with revolutionary neural networks (dsnt)
Sm59 remote connection. If you are prompted that there is no host, add host to the server and restart SAP_ SAP LIUMENG
袋鼠云数栈基于CBO在Spark SQL优化上的探索
Explore the secrets behind the open source data visualization development platform flyfish!
Opencv 4 handwriting recognition: perfect self built training set
How the terminator sets the font to display different colors
2D human posture estimation for posture estimation - associated embedding: end to end learning for joint detection and grouping