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

First re_thread_init() always fails with EALREADY #403

Closed
Lastique opened this issue Jun 18, 2022 · 4 comments · Fixed by #404
Closed

First re_thread_init() always fails with EALREADY #403

Lastique opened this issue Jun 18, 2022 · 4 comments · Fixed by #404

Comments

@Lastique
Copy link
Contributor

The check at this line:

if (re) {

always succeeds for the first re_thread_init call because re_init that is called from re_once sets the TLS pointer to the newly created re instance.

Suggestion: drop re_global and don't set TLS in re_init. Reformulate re_init to work as a factory function for creating a re context without setting it anywhere. Make the caller (e.g. re_thread_init) set it to TLS.

@Lastique
Copy link
Contributor Author

BTW, re_global can become dangling since the re context may be deleted by re_thread_close or thread termination. For example, this breaks libre_close.

@sreimers
Copy link
Member

For the main thread re_thread_init should not be called, only for additional worker threads.

re_global is needed as fallback for re_thread_enter see https://github.com/baresip/re/wiki/Development-(re-usage)#thread-safety-for-non-re-threads

@Lastique
Copy link
Contributor Author

There is no "main thread" in our case. There can be any number of threads that are running separate instances of event loop.

re_global is needed as fallback for re_thread_enter

My suggestion is to remove the fallback. Require the caller of re_thread_enter specify the re instance he wants to use until re_thread_leave. Ultimately, there would be no global state in libre (other than TLS, perhaps), and the caller would be able to explicitly create and destroy re contexts and specify the context he wants to operate on. Basically, this would properly allow for multi-instance use of libre.

@sreimers
Copy link
Member

Removing the fallback would break existing applications, like the baresip android app. Can you try this PR: #404

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

Successfully merging a pull request may close this issue.

2 participants