From 329732eef0264d044cc8ce0095e8ec56589dd400 Mon Sep 17 00:00:00 2001 From: Stefan Zabka Date: Fri, 12 Jun 2020 09:40:21 +0200 Subject: Added ppmlib.h --- 04_exercise/threadpool.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to '04_exercise/threadpool.c') diff --git a/04_exercise/threadpool.c b/04_exercise/threadpool.c index f644412..d4ee8bb 100644 --- a/04_exercise/threadpool.c +++ b/04_exercise/threadpool.c @@ -9,7 +9,7 @@ #include #include -#define MAX_FUTURES 20 +#define MAX_FUTURES 1024 typedef struct Thread { pthread_t pthread; size_t index; @@ -28,11 +28,13 @@ ThreadPool threadPool; bool isFutureWaiting(void const *vFuture) { Future *future = (Future *)vFuture; FutureStatus status = atomic_load(&future->status); + //This is racy but we'll CAS it later to make sure it's safe return status == FUT_WAITING; } void tryRunningFuture(Future *future) { char expected = FUT_WAITING; + // This can happen if multiple threads found the same Future if (!atomic_compare_exchange_strong(&future->status, &expected, FUT_IN_PROGRESS)) { return; } @@ -51,7 +53,7 @@ bool tryDoingWork() { if (future == NULL) { return false; } - // This will just return if some other thread was first as well + // This will just return if some other thread was first tryRunningFuture(future); return true; } -- cgit v1.2.3-54-g00ecf