getSolution writes head instead of where head is pointing
This commit is contained in:
parent
9cb4d66d4b
commit
8605c6e820
@ -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++;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user