brynet
brynet copied to clipboard
void brynet::net::EventLoop::loop(int64_t): Assertion `isInLoopThread()' failed. How do we make LoopThread without getting this error?
When I put an EventLoop in an std::thread like:
iothrds.emplace_back([&]
{
while (1) { ioloops[i]->loop(1); }
});
I get:
void brynet::net::EventLoop::loop(int64_t): Assertion isInLoopThread()' failed.
How do we make LoopThread the library support ? Or the Library Just handle any EventLoop created by user?
Are you already call loop in other thread? One EventLoop only loop in one thread, and if start loop ,never can't change.
The question is how do I create an EventLoop which will be using another thread entirely ?
Is it by using IOLoopData ? I saw that too
This is what I have:
void loop_test()
{
shared_ptr<thread> thrd = make_shared<thread>();
EventLoop::Ptr ioloop = std::make_shared<EventLoop>();
brynet::net::detail::IOLoopDataPtr iothrd = brynet::net::detail::IOLoopData::Create(ioloop, thrd);
ioloop->runAsyncFunctor([&]
{
fmt::print("hello\n");
});
ioloop->runAfter(1s, [&]
{
fmt::print("hello After 2s\n");
});
while(1)
{
ioloop->loop(1);
}
}
And it is working as intended
@ibroheem Hi, we must call EventLoop::loop
before runAsyncFunctor
or ``runAfter;