diff --git a/supervisor.c b/supervisor.c index 8b548b9..9a1e4be 100644 --- a/supervisor.c +++ b/supervisor.c @@ -38,6 +38,20 @@ void initCircBuf() return; } +void wait_sem(sem_t *sem) +{ + while (sem_wait(sem) == -1) { // interrupted by system call? + printf("Interupted with error!\n"); //Just to check + if (errno == EINTR) { + if(quit == 1) + exit(EXIT_SUCCESS); + else continue; + } + exit(EXIT_FAILURE); + } + return; +} + void getSolution(sem_t sUsedSpace, sem_t sFreeSpace) { int solution[MAX_ITEMS]; @@ -46,13 +60,13 @@ void getSolution(sem_t sUsedSpace, sem_t sFreeSpace) } if (shared->head == -1) { - sem_wait(&sUsedSpace); + wait_sem(&sUsedSpace); shared->head = (shared->head + 1) % MAX_ITEMS; sem_post(&sFreeSpace); } else { int i = 0; while (shared->head != -1) { - sem_wait(&sUsedSpace); + wait_sem(&sUsedSpace); solution[i] = shared->head; shared->head = (shared->head + 1) % MAX_ITEMS; sem_post(&sFreeSpace);