当前位置:网站首页>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 .
边栏推荐
- Kubernetes binary installation (v1.20.16) (V) verifying master deployment
- Rk3308--8 channels changed to dual channels + recording gain
- torch.utils.data.DataLoader()详解【Pytorch入门手册】
- Cube 技术解读 | Cube 渲染设计的前世今生
- The ultimate buff of smart grid - guanghetong module runs through the whole process of "generation, transmission, transformation, distribution and utilization"
- sm59远程连接,如果提示没有host,则在服务器上加上host,然后重启sap_SAP刘梦
- this和对象原型
- 2D human posture estimation for posture estimation - associated 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]
- Use of hardware instruments
猜你喜欢

Rk3308--8 channels changed to dual channels + recording gain

MapReduce案例之排序

Sorting of MapReduce cases

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

Rk3308-- firmware compilation

Guanghetong cooperates with China Mobile, HP, MediaTek and Intel to build 5g fully connected PC pan terminal products

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

2D human posture estimation for posture estimation - simple baseline (SBL)

Server operation and maintenance environment security system (Part 2)

影刀RPA学习和遇见excel部分问题解决方式
随机推荐
torch.nn.utils.rnn.pad_sequence()详解【Pytorch入门手册】
Jerry's ble timer clock source cannot choose OSC crystal oscillator [chapter]
json. Load (s) and json dump(s)
Beginner pytorch step pit
探索数据可视化开发平台FlyFish开源背后的秘密!
Cube 技术解读 | Cube 渲染设计的前世今生
Explore the secrets behind the open source data visualization development platform flyfish!
Jerry's ble transmission rate [chapter]
2290. Minimum Obstacle Removal to Reach Corner
【无标题】
2D human posture estimation for posture estimation - associated embedding: end to end learning for joint detection and grouping
Live broadcast preview | deconstruct OLAP! The new multidimensional analysis architecture paradigm is fully open! Apache Doris will bring five big issues!
Sorting of MapReduce cases
Thinking and precipitation after docking with hundreds of third-party APIs
Solution to some problems of shadow knife RPA learning and meeting Excel
How does the wireless communication module help the intelligent UAV build the "Internet of things in the air"?
NanoMQ Newsletter 2022-05|v0.8.0 发布,新增 WebHook 拓展接口和连接认证 API
Cap version 6.1 Release Notice
[section 14 STL container II]
Query convert quickview is a grayed out solution (turn)_ SAP LIUMENG