Skip to content
Snippets Groups Projects
Commit 19c130b9 authored by ismail.abloua's avatar ismail.abloua
Browse files

usleep, typo

parent 4d49dc71
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,8 @@
#include <time.h>
#include <unistd.h>
// structure site
typedef struct {
int available_bikes;
......@@ -44,6 +46,8 @@ void habitant_routine(void* arg) {
pthread_mutex_unlock(&sites[current_site].site_mutex);
sem_post(&sites[current_site].sem_slots);
// Travel time
usleep(1000 + rand() % 1000);
// travel to destination site
int destination_site;
do {destination_site = rand() % S;}
......@@ -56,6 +60,9 @@ void habitant_routine(void* arg) {
printf("(PUT) Habitant %d returning bike to site %d (%d bikes remaining)\n", id_habitant, current_site, sites[current_site].available_bikes);
pthread_mutex_unlock(&sites[current_site].site_mutex);
sem_post(&sites[current_site].sem_bikes);
// Activity time
usleep(1000 + rand() % 1000);
}
// finished
......@@ -71,7 +78,7 @@ void truck_routine() {
pthread_mutex_lock(&mutex_finished_habitants);
if (finished_habitants == H) {
pthread_mutex_unlock(&mutex_finished_habitants);
printf("(TRUCK) Truck leaving as all habitant have finished their routine.\n");
printf("(TRUCK) Truck leaving as all habitants have finished their routine.\n");
break;
}
pthread_mutex_unlock(&mutex_finished_habitants);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment