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

Busy Wait Forever. Problem of Scheduler. #1358

Open
mhomidi opened this issue Feb 10, 2025 · 0 comments
Open

Busy Wait Forever. Problem of Scheduler. #1358

mhomidi opened this issue Feb 10, 2025 · 0 comments

Comments

@mhomidi
Copy link
Collaborator

mhomidi commented Feb 10, 2025

This code does not work if we only start quark with cpus <= 60:

#include <iostream>
#include <thread>
#include <vector>
#include <atomic>

std::atomic<bool> run(true);

void busy_wait() {
    while (run);
}

int main() {
    std::vector<std::thread> threads;

    for (int i = 0; i < 60; ++i) {
        threads.emplace_back(busy_wait);
    }

    // Let the threads run for a short duration
    std::this_thread::sleep_for(std::chrono::seconds(5));
    run = false;

    for (auto& t : threads) {
        if (t.joinable()) {
            t.join();
        }
    }

    std::cout << "All threads completed and exited." << std::endl;
    return 0;
}

It seems that when main thread goes to sleep, it can not wake up forever. Do you have any solution for this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant