4

Can I call event_base_loopbreak to int event_base_dispatch(struct event_base *base) that run in another thread?

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
user3315755
  • 53
  • 2
  • 5
  • Adding about 2~3 lines of context makes it quite a bit more probable that people can answer your question - this is **really** concise. – Niels Keurentjes Sep 16 '14 at 07:54

3 Answers3

2

It's possible to stop event_base_dispatch with event_base_loopbreak from another thread. Just enable multithreading support by calling evthread_use_pthreads or evthread_use_windows_threads before event_base created.

  • 1
    I had this problem where event_base_loop used with EVLOOP_NO_EXIT_ON_EMPTY in another thread, is not executing events created in main thread. Once I put the evthread_use_pthreads before event_base creation phew.. it worked. Very thanks mate – King Jun 18 '20 at 05:57
1

Calling event_base_loopbreak from outside of the event loop doesn't actually have an effect and inside the loop, event_base_loopbreak does not break from the loop. So, calling event_base_loopbreak to int event_base_dispatch(struct event_base *base) that run in another thread, should not have any effect.

Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
  • 2
    So, how can I stop event_base_dispatch from another thread? OR can I add event to event_base while event_base_dispatch is working? – user3315755 Sep 16 '14 at 07:52
1

I'm also meet the same issue, no matter calling event_base_loopbreak() or event_add() from other thread are not working.

Ref to How to break out libevent's dispatch loop, I had to set a timer event before start the event loop, and polling the exit flag to call event_base_loopbreak() from the event's callback, that can exit the event loop successfully

Community
  • 1
  • 1
Liu
  • 39
  • 2