-
Notifications
You must be signed in to change notification settings - Fork 68
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
Make lib-str domain safe #635
Make lib-str domain safe #635
Conversation
I also noticed there's one case I'm not handling properly, will mark it as draft until I fixed it. |
0eab1b2
to
2f307ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went through this PR and had a discussion with @Engil offline, the gist of it is below:
Thread-local values are stored in pthread specific variable heres. This means the thread-local values will be unique not just for domains, but also for systhreads.
To be noted: systhreads access the same global state on trunk, if we'd like to replicate this behaviour I think it might be useful to have a C API for domain-local storage. It appears Str
module is currently not thread-safe in the context of systhreads and this PR would actually fixes it. We think it's all right to move forward with this approach, unless there are any alternate ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this works and solves the problem of multiple domains using str.
I had a nit about error handling should an alloc fail. Also I'm not convinced we store prev_domain_stop_hook
which is a bug.
I wonder if we could avoid global state in strstubs.c altogether, using C local variables for the initial RE engine stack and for the register array. I'll give it a try in the sequential version of OCaml. |
Are you OK to use ocaml/ocaml#10670 instead? Much less code. |
The approach taken in ocaml/ocaml#10670 looks good to me and is less code. When that gets merged upstream, we will pick it up naturally as we rebase. |
It is much cleaner than the current approach, and removes the need to add more cleanup hooks in the domain's lifecycle, thank you for this. :) |
Thanks for the confirmation. In the future I'll try to make suggestions for alternate implementations earlier! |
…e_str_domain_safe Make lib-str domain safe
…e_str_domain_safe Make lib-str domain safe
This PR moves the usage of global variables in
str
to thread local storage.The one weird part revolves around freeing the resources on domain shutdown. It make use of the previously introduced
domain_stop_hook
(for systhreads).There's also the alternative route of allocating str's internal data structures as custom blocks and letting the GC take care of these, though I'm not quite sure it is a cleaner solution.
I think adding a testcase that does some
str
computations in parallel would be useful, I will add some in the coming days.