Skip to content

[FEATURE, BUG] Busy Waiting for Worker Threads #57

@DeveloperPaul123

Description

@DeveloperPaul123

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions