1
0
mirror of https://gitlab.com/klmp200/LO41.git synced 2024-12-03 14:31:13 +00:00

Normalement c'est réglé, enfin

This commit is contained in:
Antoine Bartuccio 2018-06-22 07:13:13 +02:00
parent 7f160f69f8
commit b00cb030be
Signed by: klmp200
GPG Key ID: E7245548C53F904B
3 changed files with 23 additions and 17 deletions

View File

@ -38,7 +38,7 @@ void start_all_threads_SharedData(THIS(SharedData)){
else {
residents = this->main_building->residents;
visitors = this->main_building->visitors;
this->threads_nb = residents->get_size(residents) + visitors->get_size(visitors) + ELEVATOR_NB;
this->threads_nb = residents->get_size(residents) + visitors->get_size(visitors) + ELEVATOR_NB + 1;
this->threads = malloc_or_die(sizeof(pthread_t*) * this->threads_nb);
for (i=0; i < this->threads_nb; i++)
@ -49,12 +49,27 @@ void start_all_threads_SharedData(THIS(SharedData)){
/* starts threading elevators */
for (i=1; i<ELEVATOR_NB; i++) {
for (i=0; i<ELEVATOR_NB; i++) {
this->start_thread(this, this->main_building->elevators[i]->runnable,
this->main_building->elevators[i], i);
this->main_building->elevators[i]->set_thread_number(this->main_building->elevators[i], i);
}
/* starting the elevator breaker */
this->start_thread(this, this->elevator_breaker->runnable, this->elevator_breaker, i);
this->elevator_breaker->set_thread_number(this->elevator_breaker, i);
i++;
/* starts threading residents */
current = residents->get_head(residents);
while (current != NULL){
this->start_thread(this, ((Resident*)current->get_data(current))->runnable, current->get_data(current), i);
((Resident*)current->get_data(current))->set_thread_number((Resident*)current->get_data(current), i);
current = current->get_next(current);
this->active_passengers++;
i++;
}
/* starts threading visitors */
current = visitors->get_head(visitors);
while (current != NULL){
@ -65,19 +80,6 @@ void start_all_threads_SharedData(THIS(SharedData)){
i++;
}
/* starts threading residents */
current = residents->get_head(residents);
while (current != NULL){
this->start_thread(this, ((Resident*)current->get_data(current))->runnable, current->get_data(current), i);
((Resident*)current->get_data(current))->set_thread_number((Resident*)current->get_data(current), i);
current = current->get_next(current);
this->active_passengers++;
i++;
}
/* starting the elevator breaker */
this->start_thread(this, this->elevator_breaker->runnable, this->elevator_breaker, 0);
this->elevator_breaker->set_thread_number(this->elevator_breaker, 0);
pthread_mutex_unlock(&this->mutex_threads);
pthread_mutex_unlock(&this->mutex_active_passengers);

View File

@ -23,7 +23,11 @@ void * runnable_Visitor(void * void_this){
printf("Visiteur %s : Je souhaite rendre visite a %s\n", this->name, this->contact_name);
printf("Visiteur %s : J'apelle à l'interphone\nVisiteur %s : J'apprends que %s habite à l'étage %d\n", this->name, this->name, this->contact_name, (this->destination = data->use_call_box(data, this->contact_name)));
data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger);
if (this->destination == this->position)
printf("Visiteur %s : pas besoin de prendre l'ascenseur pour cet étage, je vais y aller à pied\n", this->name);
else
data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger);
data->decrement_active_passengers(data);
data->unregister_thread(data, this->thread_number);
return NULL;

2
main.c
View File

@ -23,7 +23,7 @@ int main(int argc, char* argv[]) {
if(argc == 3){
shared_data->set_main_building(shared_data, NEW(Building, argv[1], argv[2]));
} else if (argc == 1){
shared_data->set_main_building(shared_data, NEW(Building, "../residents.txt", "../visitors.txt"));
shared_data->set_main_building(shared_data, NEW(Building, "../Scripts/residents_500.txt", "../Scripts/visitors_500.txt"));
} else{
CRASH("Arguments invalides\nUsage : ./LO41 [residents_file visitors_file]\n");
}