summaryrefslogtreecommitdiffstats
path: root/04_exercise/threadpool.c
diff options
context:
space:
mode:
Diffstat (limited to '04_exercise/threadpool.c')
-rw-r--r--04_exercise/threadpool.c6
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;
}