当前位置:网站首页>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 ~
边栏推荐
- 2290. Minimum Obstacle Removal to Reach Corner
- Jerry's ble timer clock source cannot choose OSC crystal oscillator [chapter]
- 2D human posture estimation for posture estimation - simple baseline (SBL)
- MapReduce之分区案例的代码实现
- MapReduce案例之排序
- RK3308 按键Key与LED灯
- AttributeError: module ‘gym. envs. Box2d 'has no attribute' lunarlander 'solution
- Comply with medical reform and actively layout -- insight into the development of high-value medical consumables under the background of centralized purchase 2022
- 运行mapreduce任务缺失setJarByClass()报错找不到类
- [section 14 STL container II]
猜你喜欢
![Jerry's ble timer clock source cannot choose OSC crystal oscillator [chapter]](/img/87/9e78938faa327487e8d7045ab94bf2.png)
Jerry's ble timer clock source cannot choose OSC crystal oscillator [chapter]

Sorting of MapReduce cases
![Jerry's ble dynamic power regulation [chapter]](/img/29/22be6dca25c4e6502f076fee73dd44.png)
Jerry's ble dynamic power regulation [chapter]

RK3308 按键Key与LED灯

Methods commonly used in uniapp (part) - timestamp problem and rich text parsing image problem

leetcode:730. 统计不同回文子序列【由点及面区间dp + 三维dp + 对角线遍历】

You will never want to miss these vertical niche navigation websites

Add Anaconda's bin directory to path

The ultimate buff of smart grid - guanghetong module runs through the whole process of "generation, transmission, transformation, distribution and utilization"

使用特定大小、分辨率或背景色保存图窗
随机推荐
MapReduce之Word Count案例代码实现
[section 6 functions]
姿态估计之2D人体姿态估计 - Numerical Coordinate Regression with Convolutional 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
【历史上的今天】6 月 10 日:Apple II 问世;微软收购 GECAD;发明“软件工程”一词的科技先驱出生
22. Generate Parentheses
torch.utils.data.DataLoader()详解【Pytorch入门手册】
Server operation and maintenance environment security system (Part 2)
[MySQL basics]
torch. nn. utils. rnn. pad_ Detailed explanation of sequence() [pytoch getting started manual]
Implementation of word count case code in MapReduce
Aggregate sum of MapReduce cases
How the terminator sets the font to display different colors
Comply with medical reform and actively layout -- insight into the development of high-value medical consumables under the background of centralized purchase 2022
When visual studio 2019 is installed, vs installer cannot download files. The progress bar is 0. It shows the solutions to network problems
Join operation cases in the map phase of MapReduce
我用 MATLAB 复刻了抖音爆火小游戏 苹果蛇
[untitled]
2290. Minimum Obstacle Removal to Reach Corner
C # homework - student information management system