diff options
author | Stefan Zabka <zabkaste@hu-berlin.de> | 2020-07-10 14:24:46 +0200 |
---|---|---|
committer | Stefan Zabka <zabkaste@hu-berlin.de> | 2020-07-10 14:24:46 +0200 |
commit | 90358a35a87125c84815fd1e82a30cb17d94d918 (patch) | |
tree | a920132a7e87013b54835d481b6bc24654258e7e /04_exercise/threadpool.c | |
parent | 6937968af721c32be8b6a0247f7552470084e874 (diff) | |
download | betriebssysteme-90358a35a87125c84815fd1e82a30cb17d94d918.tar.gz betriebssysteme-90358a35a87125c84815fd1e82a30cb17d94d918.zip |
Useless committhreadpool
Diffstat (limited to '04_exercise/threadpool.c')
-rw-r--r-- | 04_exercise/threadpool.c | 8 |
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) { |