-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPeopleThread.cpp
35 lines (33 loc) · 1.13 KB
/
PeopleThread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "mainwindow.h"
PeopleThread::PeopleThread()
{
//people.desFloor = randomNum();
people.arrivalTime = v_time->GetCurVTime();
people.staytime = 0;
//wait();
}
void PeopleThread::run()
{
while(IsRunning == true)
{
QTime current = v_time->GetCurVTime();
if(- current.secsTo(people.arrivalTime) >= people.stayTime)//如果乘客在楼层的停留时间到了
{
people.sendSignal(v_time);//乘客发信号
elevatorArrived.wait();//进行等待,乘客线程被挂起,等待电梯线程的唤醒
}
current = v_time->GetCurVTime();
if(- current.secsTo(people.requestTime)<= people.tolerationTime)
{
people.getIn();
elevatorArrived.wait();
people.getOut();
}
else
{
people.arrivalTime = v_time->GetCurVTime();
qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
people.stayTime = MIN_STAY_TIME + qrand() % (MAX_STAY_TIME - MIN_STAY_TIME + 1); // 重新生成乘客在该楼层的停留时间
}
}
}