Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DeveloperPaul123 opened this issue Dec 13, 2023 · 0 comments
Open

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

DeveloperPaul123 opened this issue Dec 13, 2023 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@DeveloperPaul123
Copy link
Owner

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.

@DeveloperPaul123 DeveloperPaul123 added bug Something isn't working enhancement New feature or request labels Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant