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

Provide a callback for when the event loop is ready #1292

Closed
tristan957 opened this issue Jul 1, 2022 · 2 comments
Closed

Provide a callback for when the event loop is ready #1292

tristan957 opened this issue Jul 1, 2022 · 2 comments
Labels

Comments

@tristan957
Copy link

I am creating an HTTP server for an embedded library. I do all the event loop setup on the main thread in a function called start_server(), and then in a new thread, I run event_base_dispatch().

If my stop_server() function which calls event_base_loopbreak(), gets called before the event loop is completely setup, my library will sit at pthread_join() forever because event_base_dispatch() will never return.

I could be missing something here though.

@azat
Copy link
Member

azat commented Jul 9, 2022

If my stop_server() function which calls event_base_loopbreak(), gets called before the event loop is completely setup, my library will sit at pthread_join() forever because event_base_dispatch() will never return.

Yes, this is because event_break is reset to 0 at start and only after checked:

libevent/event.c

Lines 1979 to 1990 in 1bc62ce

base->event_gotterm = base->event_break = 0;
while (!done) {
base->event_continue = 0;
base->n_deferreds_queued = 0;
/* Terminate the loop if we have been asked to */
if (base->event_gotterm) {
break;
}
if (base->event_break) {

You can use event_base_loopexit instead, it stops loop from the loop, so it should not have such problem.

@azat azat added the type:q label Jul 9, 2022
@tristan957
Copy link
Author

tristan957 commented Jul 9, 2022

Very interesting. I thought loobreak() was the same as loopexit() with a NULL tv. This did fix my issue. That is good to know though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants