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

Assert on (! shutdown_), function schedule_from_remote #260

Open
dmitryikh opened this issue Oct 11, 2020 · 0 comments
Open

Assert on (! shutdown_), function schedule_from_remote #260

dmitryikh opened this issue Oct 11, 2020 · 0 comments

Comments

@dmitryikh
Copy link

While investigating another case just found this assert fired.
Boost fiber from develop branch.

The toy example to reproduce (some time it needs several runs):

#include <atomic>
#include <thread>
#include <chrono>
#include <iostream>
#include <boost/fiber/all.hpp>

using namespace std::chrono_literals;

int main()
{
    boost::fibers::mutex mtx;
    boost::fibers::condition_variable cond;
    std::atomic<bool> stopping;

    std::vector<std::thread> pool;
    for (size_t i = 0; i < 10; i++)
    {
        auto th = std::thread([&] ()
        {
            boost::fibers::use_scheduling_algorithm<boost::fibers::algo::shared_work>();
            auto f1 = boost::fibers::fiber([&] () {
                int i = 0;
                while (!stopping.load())
                {
                    std::cout << "trying to get lock" << std::endl;
                    std::unique_lock l(mtx);
                    std::this_thread::sleep_for(100ms);
                    std::cout << i++ << " waiting" << std::endl;
                    cond.wait_for(l, 15ms);
                    std::cout << "worker" << std::endl;
                }
            });
            f1.join();
        });
        pool.push_back(std::move(th));
    }

    auto th2 = std::thread([&] ()
    {
        while (!stopping.load())
        {
            {
                std::unique_lock l(mtx);
                cond.notify_all();
            }
            std::this_thread::sleep_for(1ms);
        }
    });

    std::this_thread::sleep_for(200ms);
    stopping.store(true);

    for (auto& th : pool)
    {
        th.join();
    }
    th2.join();

    return 0;
}

possible output:

trying to get lock
trying to get lock
trying to get lock
trying to get lock
trying to get lock
trying to get lock
trying to get lock
trying to get lock
trying to get lock
trying to get lock
0 waiting
0 waiting
0 waiting
worker
0 waiting
0 waiting
0 waiting
0 waiting
Assertion failed: (! shutdown_), function schedule_from_remote, file libs/fiber/src/scheduler.cpp, line 227.
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