retry when possible

This commit is contained in:
Mylloon 2024-05-05 14:12:00 +02:00
parent a5f7554d6b
commit 692a69a9c4
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 53 additions and 13 deletions

View file

@ -3,6 +3,7 @@
#include <assert.h> #include <assert.h>
#include <complex.h> #include <complex.h>
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
@ -120,18 +121,46 @@ draw(void *closure, struct scheduler *s)
// Sinon on recoupe le morceau // Sinon on recoupe le morceau
int mid_x = (start_x + end_x) / 2; int mid_x = (start_x + end_x) / 2;
int mid_y = (start_y + end_y) / 2; int mid_y = (start_y + end_y) / 2;
int rc;
int rc1 = sched_spawn( while((rc = sched_spawn(
draw, new_mandelbrot_args(image, start_x, start_y, mid_x, mid_y), draw,
s); new_mandelbrot_args(image, start_x, start_y, mid_x, mid_y),
int rc2 = sched_spawn( s)) < 0) {
draw, new_mandelbrot_args(image, mid_x, start_y, end_x, mid_y), s); if(errno != EAGAIN) {
int rc3 = sched_spawn( break;
draw, new_mandelbrot_args(image, start_x, mid_y, mid_x, end_y), s); }
int rc4 = sched_spawn( }
draw, new_mandelbrot_args(image, mid_x, mid_y, end_x, end_y), s); assert(rc >= 0);
assert(rc1 >= 0 && rc2 >= 0 && rc3 >= 0 && rc4 >= 0); while(
(rc = sched_spawn(
draw, new_mandelbrot_args(image, mid_x, start_y, end_x, mid_y),
s)) < 0) {
if(errno != EAGAIN) {
break;
}
}
assert(rc >= 0);
while(
(rc = sched_spawn(
draw, new_mandelbrot_args(image, start_x, mid_y, mid_x, end_y),
s)) < 0) {
if(errno != EAGAIN) {
break;
}
}
assert(rc >= 0);
while((rc = sched_spawn(
draw, new_mandelbrot_args(image, mid_x, mid_y, end_x, end_y),
s)) < 0) {
if(errno != EAGAIN) {
break;
}
}
assert(rc >= 0);
} }
} }
@ -154,7 +183,7 @@ benchmark_mandelbrot(int serial, int nthreads)
int rc; int rc;
int size = WIDTH * HEIGHT; int size = WIDTH * HEIGHT;
if(!(image = malloc(size * sizeof(unsigned int)))) { if(!(image = malloc(WIDTH * HEIGHT * sizeof(unsigned int)))) {
perror("Image allocation"); perror("Image allocation");
return 1; return 1;
} }

View file

@ -2,6 +2,7 @@
#include "../includes/sched.h" #include "../includes/sched.h"
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
@ -87,9 +88,19 @@ quicksort(void *closure, struct scheduler *s)
} }
p = partition(a, lo, hi); p = partition(a, lo, hi);
rc = sched_spawn(quicksort, new_args(a, lo, p), s);
while((rc = sched_spawn(quicksort, new_args(a, lo, p), s)) < 0) {
if(errno != EAGAIN) {
break;
}
}
assert(rc >= 0); assert(rc >= 0);
rc = sched_spawn(quicksort, new_args(a, p + 1, hi), s);
while((rc = sched_spawn(quicksort, new_args(a, p + 1, hi), s)) < 0) {
if(errno != EAGAIN) {
break;
}
}
assert(rc >= 0); assert(rc >= 0);
} }