-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-9067: random extension is not thread safe #9070
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
Conversation
For thread-safety, we need to initialize global variables in GINIT (or RINIT), but not in MINIT.
Thank you for tackling the issue. As this part of the engine is not something I have interacted with before: Do you have a reference of when example the various "callbacks" in question are executed? Is MINIT once and GINIT once per thread? |
Indeed. See https://www.phpinternalsbook.com/php7/extensions_design/php_lifecycle.html?highlight=lifecycle#globals-initialization-ginit for details. |
Thanks, I have read through that and also through the explanation for globals. I'm a little confused, because according to the link the GINIT runs before MINIT. I would have expected the reverse order (first MINIT then GINIT). But if I understand the issue and inner workings correctly:
|
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.
Based on my understanding of the PHP engine this is the correct fix. Each thread should have its own copy of the state.
Basically, yes. (Actually, it is a parameter which is an alias to the thread locals; elsewhere they're access via
Right. |
ext/random cannot be built shared, so `COMPILE_DL_RANDOM` is never defined.
For thread-safety, we need to initialize global variables in GINIT (or
RINIT), but not in MINIT.