From e52cb25c550cfd8112221c62ebb95013b9921db7 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Mon, 11 Jun 2018 02:31:03 +0200 Subject: [PATCH] Les ascenseurs en premier --- Resident/Resident.c | 2 +- SharedData/SharedData.c | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Resident/Resident.c b/Resident/Resident.c index bf588c3..c455960 100644 --- a/Resident/Resident.c +++ b/Resident/Resident.c @@ -11,7 +11,7 @@ GETTER(Resident, int, apartment_floor); void * runnable_Resident(void * void_this){ Resident * this = (Resident*) void_this; - printf("Je suis le RESIDENT %s et je suis a l'etage %d en direction de l'etage %d\n", + printf("Je suis le resident %s et je suis a l'etage %d en direction de l'etage %d\n", this->name, this->apartment_floor, this->destination); return NULL; } diff --git a/SharedData/SharedData.c b/SharedData/SharedData.c index a8c5bac..0e3c0ce 100644 --- a/SharedData/SharedData.c +++ b/SharedData/SharedData.c @@ -29,15 +29,12 @@ int call_elevator_SharedData(THIS(SharedData), int starting_floor, int destinati return 0; } -/* void * runnable_type(void* void_this) */ - void start_thread_SharedData(THIS(SharedData), void * (*thread)(void *), void * data, int thread_number){ pthread_create(&this->threads[thread_number], 0, thread, data); } void start_all_threads_SharedData(THIS(SharedData)){ int i = 0; - int elevator_index; Element * current = NULL; List * residents = NULL; List * visitors = NULL; @@ -51,6 +48,11 @@ void start_all_threads_SharedData(THIS(SharedData)){ this->threads_nb = residents->get_size(residents) + visitors->get_size(visitors) + ELEVATOR_NB; this->threads = malloc_or_die(sizeof(pthread_t) * this->threads_nb); + /* starts threading elevators */ + for (i=0; istart_thread(this, this->main_building->elevators[i]->runnable, + this->main_building->elevators[i], i); + /* starts threading visitors */ current = visitors->get_head(visitors); while (current != NULL){ @@ -66,13 +68,6 @@ void start_all_threads_SharedData(THIS(SharedData)){ current = current->get_next(current); i++; } - - /* starts threading elevators */ - for (elevator_index=0; elevator_indexstart_thread(this, this->main_building->elevators[elevator_index]->runnable, - this->main_building->elevators[elevator_index], i); - i++; - } } } }