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

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

Open
ibroheem opened this issue Feb 6, 2021 · 4 comments

Comments

@ibroheem
Copy link

ibroheem commented Feb 6, 2021

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 ibroheem changed the title void brynet::net::EventLoop::loop(int64_t): Assertion `isInLoopThread()' failed. void brynet::net::EventLoop::loop(int64_t): Assertion `isInLoopThread()' failed. How do we make LoopThread without getting this error? Feb 6, 2021
@IronsDu
Copy link
Owner

IronsDu commented Feb 7, 2021

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

@ibroheem
Copy link
Author

ibroheem commented Feb 7, 2021

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
Copy link
Author

ibroheem commented Feb 7, 2021

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

@IronsDu
Copy link
Owner

IronsDu commented Feb 8, 2021

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

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

2 participants