Write whole solutions to shared memory
This commit is contained in:
parent
10ec964fec
commit
5a9d00c48a
17
generator.c
17
generator.c
@ -170,15 +170,26 @@ void printGraph()
|
||||
}
|
||||
}
|
||||
|
||||
void putItem(sem_t sUsedSpace, sem_t sFreeSpace, sem_t sWriteEnd, int value)
|
||||
void putSolution(sem_t sUsedSpace, sem_t sFreeSpace, sem_t sWriteEnd, int *solution)
|
||||
{
|
||||
sem_wait(&sWriteEnd);
|
||||
sem_wait(&sFreeSpace);
|
||||
|
||||
if (solution[0] == -1) {
|
||||
sem_wait(&sFreeSpace);
|
||||
shared->data[shared->tail] = -1;
|
||||
shared->tail = (shared->tail + 1) % MAX_ITEMS;
|
||||
|
||||
sem_post(&sUsedSpace);
|
||||
} else {
|
||||
int i = 0;
|
||||
while (solution[i] != -1) {
|
||||
sem_wait(&sFreeSpace);
|
||||
shared->data[shared->tail] = solution[i];
|
||||
shared->tail = (shared->tail + 1) % MAX_ITEMS;
|
||||
sem_post(&sUsedSpace);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
sem_post(&sWriteEnd);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user