当前位置:网站首页>PV operation daily question - exam questions
PV operation daily question - exam questions
2022-06-10 16:10:00 【liangsena】
Test questions
I just did a simulation problem of electrical engineering , The difficulty is only moderate , But the title is a little loose , I modified it a little , If there is something wrong, please send a private letter .
One 、 Problem description
:
A school is going to have a final exam , Each examination room has N A student ,1 A teacher . In and out , Only one person can pass through the entrance of the examination room at a time , First come first served , Finish first and leave first . Regulations : When N After all the students entered the examination room , Only teachers can give out papers ; Students need to wait for the teacher's test signal before they can answer the questions ; Students can leave after handing in their papers , The teacher must wait for all the students to hand in their papers before leaving the examination room . Suppose that both teachers and students are regarded as processes , Excuse me, PV The operation solves the synchronization and mutual exclusion in the above problems , And explain the meaning of semaphore and initial value .
Two 、 problem solving
:
int count=0; // The current number of students in the examination room
semaphore empty=0; // Whether all the students in the examination room have finished
semaphore full=0; //N All the candidates arrived
semaphore start=0; // Test start signal
semaphore end=0; // Whether all exams are handed in
semaphore door=0; // Mutual exclusion in and out of the examination room
smeaphore mutexCount=0; // Exclusive access count
Student-i(int i=1,2,...,N)
{
while(1)
{
// Enter the examination room
P(door);
Entrance ;
V(door);
P(mutexCount);
count++;
if(count==N)
{
V(full);
}
V(mutexCount);
// Answer questions are handed in
if(start==1)
{
Answer the questions ;
Hand in the paper after writing ;
}
P(mutexCount);
count--;
if(count==0)
{
V(empty);
}
V(mutexCount);
// Out of the examination room
P(door);
Out of the door ;
V(door);
}
}
Teacher()
{
while(1)
{
P(door);
Entrance ;
V(door);
P(full);
Hair curls ;
start=1;
P(empty);
Seal the test paper ;
P(door);
Out of the examination room ;
V(door);
}
}
For semaphores :
- Whether a group of students have arrived 、 Finish all the exams
- A set of answer signals
- Current number of students , And mutually exclusive semaphores that access it
- Finally, the semaphore of the mutually exclusive access gate
For student progress :
- Entrance
- Waiting for the answer , Answer the questions , Hand in papers
- Out of the door
On the teacher's progress :
- Entrance
- When the students arrive , Send an answer signal
- When the students have finished , Seal the paper
- Out of the door
3、 ... and 、 twitter
This topic is a bit like the enhanced reader writer question , The process is complicated .
边栏推荐
- Cube 技术解读 | Cube 渲染设计的前世今生
- Necessary tools for automatic operation and maintenance shell script introduction
- Solution to some problems of shadow knife RPA learning and meeting Excel
- 【第14节 STL容器二】
- RK3308 按键Key与LED灯
- SVM and ANN of OpenCV neural network library_ Use of MLP
- [section 6 functions]
- 姿态估计之2D人体姿态估计 - Numerical Coordinate Regression with Convolutional Neural Networks(DSNT)
- Opencv 4 handwriting recognition: perfect self built training set
- torch.utils.data.DataLoader()详解【Pytorch入门手册】
猜你喜欢

使用特定大小、分辨率或背景色保存图窗

【MySQL基础】

直播預告 | 解構OLAP!新型多維分析架構範式全公開!Apache Doris 將帶來五個重磅議題!

“绽放杯”5G应用奖项大满贯!广和通多个联合项目荣获通用产品专题赛一、二、三等奖

Join operation cases in the reduce phase of MapReduce

Comply with medical reform and actively layout -- insight into the development of high-value medical consumables under the background of centralized purchase 2022
Cap version 6.1 Release Notice
![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]

Opencv 4 handwriting recognition: perfect self built training set

Explore the secrets behind the open source data visualization development platform flyfish!
随机推荐
sm59远程连接,如果提示没有host,则在服务器上加上host,然后重启sap_SAP刘梦
【无标题】
Cap version 6.1 Release Notice
[MySQL basics]
我用 MATLAB 复刻了抖音爆火小游戏 苹果蛇
2D human posture estimation for posture estimation - simple baseline (SBL)
leetcode:730. Statistics of different palindrome subsequences [traversed by point and surface interval DP + 3D DP + diagonal]
Click to unlock "keyword" of guanghetong 5g module
MapReduce案例之聚合求和
MapReduce之分区案例的代码实现
Interpretation of cube technology | past and present life of cube Rendering Design
姿态估计之2D人体姿态估计 - Associative Embedding: End-to-End Learning for Joint Detection and Grouping
Google x open source grabbing manipulator can find the target part at a glance without manual marking [turn]
【无标题】
【第六节 函数】
软件测试架构师,给后辈的16条忠告,快看看别错过
Rk3308--8 channels changed to dual channels + recording gain
Use of hardware instruments
广和通携手中国移动、惠普、联发科、英特尔合作打造5G全互联PC泛终端系列产品
作用域和闭包