问题
Can I call event_base_loopbreak
to int event_base_dispatch(struct event_base *base)
that run in another thread?
回答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.
回答2:
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
回答3:
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.
来源:https://stackoverflow.com/questions/25863215/break-event-base-dispatch-from-another-thread