Break event_base_dispatch from another thread

孤人 提交于 2020-01-30 05:58:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!