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

Debug mode option to error on evthread init AFTER other event calls. #251

Merged
merged 1 commit into from May 29, 2015
Merged

Debug mode option to error on evthread init AFTER other event calls. #251

merged 1 commit into from May 29, 2015

Conversation

errzey
Copy link
Contributor

@errzey errzey commented May 15, 2015

This is a proposed solution to #191

  • A handy event_enable_debug_mode() feature which will error and abort the
    application if any thread-aware libevent functions are called BEFORE the
    evthread API has been initialized (manually, or through
    evthread_use_windows_threads() / evthread_use_pthreads()
  • This is done by setting the global debug variable
    'event_debug_created_threadable_ctx_' whenever the following functions
    are called:
    • evthreadimpl_lock_alloc_()
    • evthreadimpl_cond_alloc_()
    • event_base_new_with_config() (since this checks to see if the thread
      callbacks are enabled, we have to manually set the variable)
  • Example:
int main(int argc, char ** argv) {
    struct event_base * base;

    event_enable_debug_mode();

    base = event_base_new();

    evthread_use_pthreads();

    return 0;
}

When executed, the program will throw an error and exit:

[err] evthread initialization must be called BEFORE anything else!

I will spend more time looking for other entry points I might have missed.

- A handy event_enable_debug_mode() feature which will error and abort the
  application if any thread-aware libevent functions are called BEFORE the
  evthread API has been initialized (manually, or through
  evthread_use_windows_threads() / evthread_use_pthreads()

- This is done by setting the global debug variable
  'event_debug_created_threadable_ctx_' whenever the following functions
  are called:

     evthreadimpl_lock_alloc_()
     evthreadimpl_cond_alloc_()
     event_base_new_with_config() <- this checks to see if the thread
                                     callbacks are enabled first, so we
                                     have to manually set the variable.

- Example:

int main(int argc, char ** argv) {
    struct event_base * base;

    event_enable_debug_mode();

    base = event_base_new();

    evthread_use_pthreads();

    return 0;
}

When executed, the program will throw an error and exit:

[err] evthread initialization must be called BEFORE anything else!
@errzey
Copy link
Contributor Author

errzey commented May 27, 2015

@nmathewson any issue with this that you can see?

@errzey
Copy link
Contributor Author

errzey commented May 29, 2015

Merging. I feel as if debugging stuff should be tweaked a bit in the future, rid ourselves of the global vars.

errzey pushed a commit that referenced this pull request May 29, 2015
Debug mode option to error on evthread init AFTER other event calls.
@errzey errzey merged commit c6fffc7 into libevent:master May 29, 2015
@errzey errzey deleted the 21_err_on_thread_init_ordering branch May 29, 2015 13:47
@errzey errzey restored the 21_err_on_thread_init_ordering branch May 29, 2015 13:47
@errzey errzey deleted the 21_err_on_thread_init_ordering branch May 29, 2015 13:47
@azat azat modified the milestone: 2.1 May 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants