Open dmitryikh opened 4 years ago
I was able to extract minimal example that reproduces the assert:
#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;
auto th1 = std::thread([&] ()
{
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::cout << i++ << " waiting" << std::endl;
cond.wait_for(l, 15ms);
std::cout << "worker" << std::endl;
}
});
auto f2 = boost::fibers::fiber([&] () {
int i = 0;
while (!stopping.load())
{
std::cout << "trying to get lock" << std::endl;
std::unique_lock l(mtx);
std::cout << i++ << " waiting" << std::endl;
cond.wait_for(l, 15ms);
std::cout << "worker" << std::endl;
}
});
f1.join();
f2.join();
});
auto th2 = std::thread([&] ()
{
while (!stopping.load())
{
{
std::unique_lock l(mtx);
cond.notify_all();
}
std::this_thread::sleep_for(1ms);
}
});
auto th3 = std::thread([&] ()
{
while (!stopping.load())
{
{
std::unique_lock l(mtx);
cond.notify_all();
}
std::this_thread::sleep_for(1ms);
}
});
std::cout << "Press any key" << std::endl;
std::cin.get();
stopping.store(true);
th1.join();
th2.join();
th3.join();
return 0;
}
possible output:
...
298 waiting
worker
trying to get lock
290 waiting
Assertion failed: (! ctx->remote_ready_is_linked()), function sleep2ready_, file libs/fiber/src/scheduler.cpp, line 87.
[1] 53769 abort bin/test_case
...
Situation:
fibers running in TP is waiting on cond_var:
If I build the program with assertions I got very fast the assert:
As far As I understand the fiber can be waked up by timer or by notification from another thread and this is not allowed by this assert. How can I fix the issue?
P.S. When I changed wait_for() -> wait() the assert is gone!
Thanks!