Read whole solutions from shared memory
This commit is contained in:
parent
a8d8999fa1
commit
699d1b9ed4
20
supervisor.c
20
supervisor.c
@ -36,18 +36,24 @@ void initCircBuf()
|
||||
return;
|
||||
}
|
||||
|
||||
int getItem(sem_t sUsedSpace, sem_t sFreeSpace)
|
||||
void getSolution(sem_t sUsedSpace, sem_t sFreeSpace, int *solution)
|
||||
{
|
||||
if (shared->head == -1) {
|
||||
sem_wait(&sUsedSpace);
|
||||
|
||||
int value;
|
||||
|
||||
value = shared->data[shared->head];
|
||||
shared->head = (shared->head + 1) % MAX_ITEMS;
|
||||
|
||||
sem_post(&sFreeSpace);
|
||||
} else {
|
||||
int i = 0;
|
||||
while (shared->head != -1) {
|
||||
sem_wait(&sUsedSpace);
|
||||
solution[i] = shared->head;
|
||||
shared->head = (shared->head + 1) % MAX_ITEMS;
|
||||
sem_post(&sFreeSpace);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
// Code for testing wether new solution is better than old
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user