diff --git a/generator.c b/generator.c index 8453f66..72b4d73 100644 --- a/generator.c +++ b/generator.c @@ -13,13 +13,13 @@ static const char *pname; static struct circ_buf *shared; -static int shmfd; +int shmfd; -static sem_t *sUsedSpace; +sem_t *sUsedSpace; -static sem_t *sFreeSpace; +sem_t *sFreeSpace; -static sem_t *sWriteEnd; +sem_t *sWriteEnd; struct sigaction sa; @@ -223,6 +223,9 @@ void wait_sem(sem_t *sem) void putSolution(int *solution) { + if (shared->quit == 1) + return; + wait_sem(sWriteEnd); for (int i = 0; i < MAX_ITEMS; i++) { diff --git a/supervisor.c b/supervisor.c index 063551a..3e8390d 100644 --- a/supervisor.c +++ b/supervisor.c @@ -12,13 +12,13 @@ static const char *pname; struct circ_buf *shared; -static int shmfd; +int shmfd; -static sem_t *sUsedSpace; +sem_t *sUsedSpace; -static sem_t *sFreeSpace; +sem_t *sFreeSpace; -static sem_t *sWriteEnd; +sem_t *sWriteEnd; struct sigaction sa; @@ -121,12 +121,11 @@ void getSolution(sem_t *sUsedSpace, sem_t *sFreeSpace) // Compute length of newSolution if (solution[0] != -1) { - for (int i = 0; i < MAX_ITEMS; i++) { - if (solution[i] == -1) { - newSolutionLength = i; - break; - } + int i = 0; + while ((solution[i] != -1) && (i != (MAX_ITEMS - 1))) { + i++; } + newSolutionLength = i; } if (newSolutionLength == 0) {