


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



2
3
-^ reorder.c
-^ double-check.c
4
5
-^ Prof. Jim Plank’s elevator simulation framework: >^ elevator^ nfloors
nelevators interarrival
opentime floor_to_floor
duration^ seed
-^ nfloors : Number of floors in the building•^ ( int^ greater than one). –^ nelevators : Number of elevators in the building•^ ( int^ greater than zero). –^ interarrival : Average interarrival time in seconds of people•^ ( double^ greater than zero). –^ opentime : Time in seconds for an elevator to open or close its doors•^ ( double^ greater than zero). –^ floor_to_floor
: Time in seconds for an elevator to to an adjacent floor• ( double greater than zero).
-^ duration : Time in seconds to simulate•^ ( double^ greater than zero). –^ seed : Seed for random number generator•^ ( int )
6
st
7
//people inter-arrival time double door_time;
//time to open/close door double floor_to_floor_time;
//time to go to adjacent floor int npeople_started;
// Stats int npeople_finished;pthread_mutex_t *lock;void *v;^
// For you to define
8
typedef struct {int id;^
/*^ Elevator id */ int onfloor;^
/*^ elevator’s current floor */ int door_open;
/*^ Whether the door is open */ int moving;^
/*^ Whether the elevator is moving */ Dllist people;
/*^ Dllist of people on the elevator */
13
14
*es):
-^ set up the global person list and a condition variable for blocking elevators • void wait_for_elevator(Person
*p):
-^ append the person to the global list–^ signal elevators that people are ready–^ block for elevator on the person's condition variable • void wait_to_get_off_elevator(Person *p)
-^ notify elevator that you are on it: signal your elevator's condition variable–^ wait for elevator to arrive: block on the person's condition variable • void person_done(Person
*p):
-^ Unblock the elevator's condition variable. • void *elevator(void *arg)
-^ check the global list;^ •^ if empty, block on condition variable for blocking elevators•^ if not empty:–^ take first person of global person’s list; put self in person’s “elevator” field–^ move to person’s floor–^ open door–^ notiyf person to get on and wait until the person is on–^ move to person's destination floor–^ opens door, notify person to get off–^ wait for person to get off–^ close door
15
16