Write whole solution to shared memory and -1 if acyclic
This commit is contained in:
parent
db393a0b43
commit
3af17e0d84
18
generator.c
18
generator.c
@ -170,12 +170,26 @@ void printGraph()
|
||||
}
|
||||
}
|
||||
|
||||
void putSolution(sem_t sUsedSpace, sem_t sFreeSpace, int *solution)
|
||||
void putSolution(sem_t sUsedSpace, sem_t sFreeSpace, sem_t sWriteEnd, int *solution)
|
||||
{
|
||||
shared->data[shared->tail] = itemValue;
|
||||
sem_wait(&sWriteEnd);
|
||||
sem_wait(&sFreeSpace);
|
||||
|
||||
if (solution[0] == -1) {
|
||||
shared->data[shared->tail] = -1;
|
||||
shared->tail = (shared->tail + 1) % MAX_ITEMS;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while (solution[i] != -1) {
|
||||
shared->data[shared->tail] = solution[i];
|
||||
shared->tail = (shared->tail + 1) % MAX_ITEMS;
|
||||
}
|
||||
|
||||
sem_post(&sUsedSpace);
|
||||
sem_post(&sWriteEnd);
|
||||
}
|
||||
|
||||
void cleanup()
|
||||
{
|
||||
for (int v = 0; v < graph.V; v++) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user