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.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/04_exercise/threadpool.c b/04_exercise/threadpool.c
index d40b1da..f046235 100644
--- a/04_exercise/threadpool.c
+++ b/04_exercise/threadpool.c
@@ -54,8 +54,11 @@ bool tryDoingWork() {
if (entry == NULL) {
return false;
}
- Future * fut = (Future *) entry->value;
+ Future * fut = (Future *)atomic_load(&entry->value);
// This will just return if some other thread was first
+ if(fut == NULL) {
+ return false;
+ }
return tryRunningFuture(fut);
}
/** @brief worker function running in the threadpool
@@ -66,7 +69,7 @@ _Noreturn void *poolWorkerFunc(void *v_index) {
unsigned int backoffTime = 1;
while (true) {
if (!tryDoingWork()) {
- backoffTime = 2 * backoffTime;
+ // backoffTime = 2 * backoffTime;
fprintf(stderr, "Thread %zu: Found no work sleeping for %d seconds \n",
index, backoffTime);
sleep(backoffTime);
@@ -114,6 +117,7 @@ void tpAsync(Future *future) {
while (smInsert(&threadPool.header, (void *)future) < 0) {
tryDoingWork();
}
+ sched_yield();
}
void tpAwait(Future *future) {