aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2009-10-03 20:39:47 +0000
committerDimitri Sokolyuk <demon@dim13.org>2009-10-03 20:39:47 +0000
commit6869d4cfe87be85d461c490ea87a8447e72475f3 (patch)
tree29495cc98b7a2110777b419e3f738a418b21d005
parent9b46e5890d5f2e202c5927ced705eef69149800c (diff)
fix memory leak
-rw-r--r--weasel.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/weasel.c b/weasel.c
index fe00e22..f6b38ff 100644
--- a/weasel.c
+++ b/weasel.c
@@ -28,6 +28,7 @@
#define NUM_THREADS 10
pthread_t threads[NUM_THREADS];
pthread_mutex_t mutexsum;
+pthread_attr_t attr;
struct intargs {
int mutationrate;
@@ -194,7 +195,6 @@ ptintercourse(void *args)
pthread_exit(NULL);
}
-
int
main(int argc, char **argv)
{
@@ -227,17 +227,24 @@ main(int argc, char **argv)
args.population = population;
args.mutationrate = mutationrate;
+ pthread_mutex_init(&mutexsum, NULL);
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
for (i = 0;; i++) {
move(0, 0);
for (t = 0; t < NUM_THREADS; t++)
- pthread_create(&threads[t], NULL, ptintercourse, (void *)&args);
+ pthread_create(&threads[t], &attr, ptintercourse, (void *)&args);
printpopulation(LINES - 8);
if (success())
break;
refresh();
}
+ pthread_attr_destroy(&attr);
+ pthread_mutex_destroy(&mutexsum);
+
printw("\nhalted after %d generations\n", NUM_THREADS * i / population);
refresh();
endwin();