brynet icon indicating copy to clipboard operation
brynet copied to clipboard

void brynet::net::EventLoop::loop(int64_t): Assertion `isInLoopThread()' failed. How do we make LoopThread without getting this error?

Open ibroheem opened this issue 3 years ago • 4 comments

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?

ibroheem avatar Feb 06 '21 17:02 ibroheem

Are you already call loop in other thread? One EventLoop only loop in one thread, and if start loop ,never can't change.

IronsDu avatar Feb 07 '21 00:02 IronsDu

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

ibroheem avatar Feb 07 '21 16:02 ibroheem

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 avatar Feb 07 '21 20:02 ibroheem

@ibroheem Hi, we must call EventLoop::loop before runAsyncFunctor or ``runAfter;

IronsDu avatar Feb 08 '21 01:02 IronsDu