当前位置:网站首页>PV operation daily question 1 - single wooden bridge problem (variant 2)
PV operation daily question 1 - single wooden bridge problem (variant 2)
2022-06-10 16:11:00 【liangsena】
Variant II of the single log 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 . And the vehicles in all directions are required to cross the bridge in series , But when the other side offered to cross the bridge , It shall be able to prevent the other party's successor vehicles that have not been on the bridge , After the vehicles on the bridge deck pass , The car on the other side began to cross the bridge .
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 pass=1; // It is used to block the other party's subsequent vehicles from getting on the bridge
East()
{
while(1)
{
P(pass)
P(eastMutex);
if(eastCount==0)
{
P(bridge);
}
eastCount++;
V(eastMutex);
V(pass);
P(maxNum);
Cross the bridge from the East ;
V(maxNum);
P(eastMutex);
eastCount--;
if(eastCount==0)
{
P(bridge);
}
V(eastMutex);
}
}
West()
{
while(1)
{
P(pass);
P(westMutex);
if(westCount==0)
{
P(bridge);
}
westCount++;
V(eastMutex);
V(pass);
P(maxNum);
Cross the bridge from the West ;
V(maxNum);
P(westMutex);
westCount--;
if(westCount==0)
{
P(bridge);
}
V(westMutex);
}
}
3、 ... and 、 twitter
pass Semaphore , When one party wants to cross the bridge, apply first , If you can't apply, it means that you have been blocked by the other party . Also apply to pass, Then block the other party's progress .
边栏推荐
- Implementation of word count case code in MapReduce
- Guanghetong cooperates with China Mobile, HP, MediaTek and Intel to build 5g fully connected PC pan terminal products
- Comply with medical reform and actively layout -- insight into the development of high-value medical consumables under the background of centralized purchase 2022
- Android 13 re upgrade for intent filters security
- 运行mapreduce任务缺失setJarByClass()报错找不到类
- Detailed installation steps of mysql8
- This and object prototypes
- Google X开源抓取机械臂,无需人工标注就能一眼找到目标零件[转]
- 软件测试架构师,给后辈的16条忠告,快看看别错过
- Apache atlas quick start
猜你喜欢

作用域和闭包

sm59远程连接,如果提示没有host,则在服务器上加上host,然后重启sap_SAP刘梦

What has guanghetong done in the three years of 5g business from "seeding in the first generation" to "flower on the ground"?

The command set has reached strategic cooperation with Yingmin technology, and the domestic original Internet of things operating system has helped to make power detection "intelligent"

Aperçu en direct | déconstruire OLAP! Le nouveau paradigme de l'architecture d'analyse multidimensionnelle est entièrement ouvert! Apache Doris va apporter cinq gros problèmes!

【历史上的今天】6 月 10 日:Apple II 问世;微软收购 GECAD;发明“软件工程”一词的科技先驱出生

Guanghetong high computing power intelligent module injects intelligence into 5g c-v2x in the trillion market

Unified certification center oauth2 certification pit

SVM and ANN of OpenCV neural network library_ Use of MLP

Smart home (3) competitive product analysis of Intelligent Interaction
随机推荐
Analysis of different dimensions of enterprise reviewers: enterprise growth of Hunan Great Wall Science and Technology Information Co., Ltd
Sword finger offer 06 Print linked list from end to end
点击解锁广和通5G模组“关键词”
Join operation cases in the map phase of MapReduce
Interpretation of cube technology | past and present life of cube Rendering Design
What has guanghetong done in the three years of 5g business from "seeding in the first generation" to "flower on the ground"?
Jerry's ble abnormal power consumption [chapter]
[MySQL basics]
Code implementation of partition case of MapReduce
Query-Convert QuickView是灰掉的解决办法(转)_SAP刘梦
Thinking and precipitation after docking with hundreds of third-party APIs
Jerry's ble dynamic power regulation [chapter]
MapReduce案例之聚合求和
测试用例常用方法和选择原则
Guanghetong high computing power intelligent module injects intelligence into 5g c-v2x in the trillion market
Aggregate sum of MapReduce cases
Jerry's ble transmission rate [chapter]
Rk3308--8 channels changed to dual channels + recording gain
[section 6 functions]
【第14节 STL容器二】