From 47aaae2c42d554963fb811b68fdf28c9743598e8 Mon Sep 17 00:00:00 2001 From: Stefan Zabka Date: Wed, 10 Jun 2020 17:10:02 +0200 Subject: Starting threadpool --- 04_exercise/main.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 04_exercise/main.c (limited to '04_exercise/main.c') diff --git a/04_exercise/main.c b/04_exercise/main.c new file mode 100644 index 0000000..cdcaa42 --- /dev/null +++ b/04_exercise/main.c @@ -0,0 +1,27 @@ +#include "threadpool.h" + +#include +#include + +static TASK(long, fib, long); + +long fib(long n) { + if (n <= 1) + return n; + + fib_fut *a = fibAsync((fib_fut[]) { fibFuture(n - 1) }); + fib_fut *b = fibAsync((fib_fut[]) { fibFuture(n - 2) }); + + return fibAwait(a) + fibAwait(b); +} + +int main() { + if (tpInit(8) != 0) + perror("Thread Pool initialization failed"), exit(-1); + atexit(&tpRelease); + + for (long i = 0; i <= 20; ++i) + printf("fib(%2li) = %li\n", i, fib(i)); + + return 0; +} -- cgit v1.2.3-54-g00ecf