diff --git a/multibrot.c b/multibrot.c index a6bb2ca..772c528 100644 --- a/multibrot.c +++ b/multibrot.c @@ -38,6 +38,7 @@ void compmandelbrot_line(bitmap_t * mbrot, size_t y) { bool diverges = false; float complex z = 0; + int it; for (it = 1; it <= max_it; it++) { /* z = z² + c */ @@ -62,6 +63,9 @@ void compmandelbrot_line(bitmap_t * mbrot, size_t y) { } } +/* Mandelbrot bitmap. */ +bitmap_t *mbrot; + /* Next line to compute. */ size_t next_y = 0; @@ -70,8 +74,6 @@ pthread_mutex_t next_y_mutex; /* Thread to compute mandelbrot. */ void *compmandelbrot(void *arg) { - bitmap_t *mbrot = (bitmap_t *) arg; - size_t y = 0; while (y < mbrot->height) { int ret; @@ -191,11 +193,11 @@ int main(int argc, char *argv[]) { } /* Set up mandelbrot bitmap. */ - bitmap_t mbrot; - mbrot.width = 1600; - mbrot.height = 1200; - mbrot.pixels = calloc(sizeof(pixel_t), mbrot.width * mbrot.height); - assert(mbrot.pixels != NULL); + mbrot = calloc(sizeof(bitmap_t), 1); + mbrot->width = 1600; + mbrot->height = 1200; + mbrot->pixels = calloc(sizeof(pixel_t), mbrot->width * mbrot->height); + assert(mbrot->pixels != NULL); /* Start computing threads. */ int ret; @@ -207,7 +209,7 @@ int main(int argc, char *argv[]) { for (int t = 0; t < num_threads; t++) { ret = - pthread_create(&threads[t], NULL, compmandelbrot, (void *) &mbrot); + pthread_create(&threads[t], NULL, compmandelbrot, (void *) NULL); assert(ret == 0); } @@ -219,13 +221,14 @@ int main(int argc, char *argv[]) { /* Save PNG */ char *file = "multibrot.png"; - ret = save_png_to_file(&mbrot, file); + ret = save_png_to_file(mbrot, file); assert(ret == 0); /* Quit. */ pthread_exit(NULL); free(threads); - free(mbrot.pixels); + free(mbrot->pixels); + free(mbrot); ret = pthread_mutex_destroy(&next_y_mutex); assert(ret == 0); return 0;