getSolution writes head instead of where head is pointing

This commit is contained in:
zenon 2018-06-08 10:21:33 +02:00
parent 9cb4d66d4b
commit 8605c6e820

View File

@ -91,15 +91,15 @@ void getSolution(sem_t *sUsedSpace, sem_t *sFreeSpace)
solution[i] = -1;
}
if (shared->head == -1) {
if (shared->data[shared->head] == -1) {
wait_sem(sUsedSpace);
shared->head = (shared->head + 1) % MAX_ITEMS;
sem_post(sFreeSpace);
} else {
int i = 0;
while (shared->head != -1) {
while (shared->data[shared->head] != -1) {
wait_sem(sUsedSpace);
solution[i] = shared->head;
solution[i] = shared->data[shared->head];
shared->head = (shared->head + 1) % MAX_ITEMS;
sem_post(sFreeSpace);
i++;