diff --git a/one_armed_bandit.c b/one_armed_bandit.c index 50d7db9c16abd67c99b881f0fe4810ee0cf88135..0c6d7bc53dddb5b8f72a5d8d59f15e50128027de 100644 --- a/one_armed_bandit.c +++ b/one_armed_bandit.c @@ -40,7 +40,7 @@ int stopped_wheels(machine mas){ int main() { - int wheel_turn = 4; + int wheel_turn = WHEEL_NB + 1; bool paid = false; bool quit=false; pthread_t threads[WHEEL_NB + 1]; @@ -114,5 +114,10 @@ int main() } } while(!quit); + sem_destroy(&(mas.semaphore)); + for (int i = 0; i < WHEEL_NB; i++) { + pthread_mutex_destroy(&(mas.wheels[i].lock)); + } + return 0; } diff --git a/wheel.h b/wheel.h index 0f3961749fbdcd84c604fb6891d1699ba97713e7..89b84e0e629e34e3c6ca4859d4ece9069f0dae92 100644 --- a/wheel.h +++ b/wheel.h @@ -12,9 +12,9 @@ typedef struct roue{ int current_px; // used to synchronize cache with memory so display is always up to date pthread_mutex_t lock; - + // used to make the thread wait when the wheel is not spinning sem_t* semaphore; - + // used to securely exit the game bool* end; } wheel;