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

Destructor sometimes hangs #1

Open
pfeatherstone opened this issue Dec 9, 2024 · 0 comments
Open

Destructor sometimes hangs #1

pfeatherstone opened this issue Dec 9, 2024 · 0 comments

Comments

@pfeatherstone
Copy link

pfeatherstone commented Dec 9, 2024

The destructor of task_system can sometimes hang. So i believe there is a race somewhere. I'm using the following code where "Done" is sometimes not printed.

{
    ts::task_system tp;

    const size_t ntests = 1000000;
    std::atomic<size_t>     counter = 0;
    std::mutex              lock;
    std::condition_variable event;
    bool                    done{false};

    const auto start = high_resolution_clock::now();

    for (size_t i = 0 ; i < ntests ; ++i)
    {
        tp.schedule([&] {
            ++counter;

            if (counter == ntests)
            {
                {
                    std::unique_lock l{lock};
                    done = true;
                }
                event.notify_one();
            }
        });
    }

    printf("Enqueued all tasks...\n");
    {
        std::unique_lock l{lock};
        event.wait(l, [&]{return done;});
    }
    const auto stop = high_resolution_clock::now();
    const auto delta = duration_cast<milliseconds>(stop-start).count() * 1e-3;
    printf("Enqueued all tasks... Done in %f seconds\n", delta);
}
printf("Done\n");
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