Generator(s) no properly exit(s)
This commit is contained in:
parent
8277a26ed2
commit
d6674d7aa4
30
generator.c
30
generator.c
@ -181,6 +181,8 @@ void printGraph()
|
|||||||
|
|
||||||
void cleanup()
|
void cleanup()
|
||||||
{
|
{
|
||||||
|
sem_post(sWriteEnd);
|
||||||
|
sem_post(sFreeSpace);
|
||||||
for (int v = 0; v < graph.V; v++) {
|
for (int v = 0; v < graph.V; v++) {
|
||||||
struct AdjListNode *pCrawl = graph.array[v].head;
|
struct AdjListNode *pCrawl = graph.array[v].head;
|
||||||
struct AdjListNode *tmp;
|
struct AdjListNode *tmp;
|
||||||
@ -202,6 +204,8 @@ void cleanup()
|
|||||||
sem_close(sUsedSpace);
|
sem_close(sUsedSpace);
|
||||||
sem_close(sFreeSpace);
|
sem_close(sFreeSpace);
|
||||||
sem_close(sWriteEnd);
|
sem_close(sWriteEnd);
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -223,13 +227,20 @@ void wait_sem(sem_t *sem)
|
|||||||
|
|
||||||
void putSolution(int *solution)
|
void putSolution(int *solution)
|
||||||
{
|
{
|
||||||
if (shared->quit == 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
wait_sem(sWriteEnd);
|
wait_sem(sWriteEnd);
|
||||||
|
|
||||||
|
if (shared->quit == 1) {
|
||||||
|
quit = 1;
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < MAX_ITEMS; i++) {
|
for (int i = 0; i < MAX_ITEMS; i++) {
|
||||||
wait_sem(sFreeSpace);
|
wait_sem(sFreeSpace);
|
||||||
|
if (shared->quit == 1) {
|
||||||
|
quit = 1;
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
shared->data[shared->tail] = solution[i];
|
shared->data[shared->tail] = solution[i];
|
||||||
shared->tail = (shared->tail + 1) % MAX_ITEMS;
|
shared->tail = (shared->tail + 1) % MAX_ITEMS;
|
||||||
sem_post(sUsedSpace);
|
sem_post(sUsedSpace);
|
||||||
@ -249,6 +260,11 @@ int findIndex(int array[], int value, int size)
|
|||||||
|
|
||||||
void genSolution(int permutation[], int V, int *solution)
|
void genSolution(int permutation[], int V, int *solution)
|
||||||
{
|
{
|
||||||
|
if (shared->quit == 1) {
|
||||||
|
quit = 1;
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
// initialize array to indices
|
// initialize array to indices
|
||||||
@ -285,14 +301,6 @@ void genSolution(int permutation[], int V, int *solution)
|
|||||||
pCrawl = pCrawl->next;
|
pCrawl = pCrawl->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
printf("[");
|
|
||||||
for (int i = 0; i < (count - 1); i++) {
|
|
||||||
printf("%d, ", solution[i]);
|
|
||||||
}
|
|
||||||
printf("%d]\n", solution[count-1]);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|||||||
@ -41,6 +41,9 @@ void usage(void)
|
|||||||
void cleanup()
|
void cleanup()
|
||||||
{
|
{
|
||||||
shared->quit = 1;
|
shared->quit = 1;
|
||||||
|
sem_wait(sUsedSpace);
|
||||||
|
sem_post(sWriteEnd);
|
||||||
|
sem_post(sFreeSpace);
|
||||||
|
|
||||||
if (munmap(shared, sizeof(*shared)) == -1) {
|
if (munmap(shared, sizeof(*shared)) == -1) {
|
||||||
perror("munmap");
|
perror("munmap");
|
||||||
@ -58,6 +61,8 @@ void cleanup()
|
|||||||
sem_unlink(SEM_USED_SPACE);
|
sem_unlink(SEM_USED_SPACE);
|
||||||
sem_unlink(SEM_FREE_SPACE);
|
sem_unlink(SEM_FREE_SPACE);
|
||||||
sem_unlink(SEM_WRITE_END);
|
sem_unlink(SEM_WRITE_END);
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initCircBuf()
|
void initCircBuf()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user