diff options
author | Stefan Zabka <zabkaste@hu-berlin.de> | 2020-06-12 09:40:21 +0200 |
---|---|---|
committer | Stefan Zabka <zabkaste@hu-berlin.de> | 2020-06-12 09:40:21 +0200 |
commit | 329732eef0264d044cc8ce0095e8ec56589dd400 (patch) | |
tree | 045a4942c936e982d03367e6efdf087240967c47 /04_exercise/threadpool.c | |
parent | 781a3f28a0f465350bf617b1f2c9ff70c0fbde9b (diff) | |
download | betriebssysteme-329732eef0264d044cc8ce0095e8ec56589dd400.tar.gz betriebssysteme-329732eef0264d044cc8ce0095e8ec56589dd400.zip |
Added ppmlib.h
Diffstat (limited to '04_exercise/threadpool.c')
-rw-r--r-- | 04_exercise/threadpool.c | 6 |
1 files changed, 4 insertions, 2 deletions
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 <stdlib.h> #include <unistd.h> -#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; } |