generated from TheLartians/ModernCppStarter
-
-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request
Description
Currently, the thread pool will eventually deadlock if a user launches a tasks that recursively creates new tasks on the thread pool wait for a result.
Sample code:
// see
// https://github.com/DevShiftTeam/AppShift-MemoryPool/commit/ea5908cbbd1c9163e9bc700d102e97b53e737fe5
int fib_thread_loop(int n, dp::thread_pool<>& pool) {
if (n <= 1) return n;
auto a = pool.enqueue(fib_thread_loop, n - 1, std::ref(pool));
auto b = pool.enqueue(fib_thread_loop, n - 2, std::ref(pool));
return a.get() + b.get();
}
TEST_CASE("Recursive fibonacci sequence") {
dp::thread_pool pool{};
auto result = fib_thread_loop(4, pool);
CHECK(result == 3);
}This is also discussed in #56 .
We could possible get around this with a custom promise and future, or we could potentially use coroutines internally to allow for busy waiting.
UMU618
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingenhancementNew feature or requestNew feature or request