-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Making ENV Ractor-safe #4636
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
Making ENV Ractor-safe #4636
Conversation
Is there any performance impact for non-Ractor code? |
Also, does this mean you can use |
There is some performance impact, but the level of impact varies between methods. For some methods, it seems negligible. For others, there is a visible impact on speed, but for many of these the impact is comparatively insignificant when ENV is larger (because the overhead from the locks remains constant). |
Yes, it would be possible to have one Ractor store a value/message in ENV and have another Ractor read it. |
* --braces-after-func-def-line * --space-after-for
static void | ||
copy_env_pairs(const char **arr, int size) | ||
{ | ||
char **env; | ||
env = GET_ENVIRON(environ); | ||
for (int i = 0; i < size; i++) { | ||
const char *p = *env; | ||
arr[i] = p; | ||
env++; | ||
} | ||
FREE_ENVIRON(environ); | ||
} |
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.
Copied entries may no longer be valid once other threads change any envs.
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.
More accurately, this function doesn't copy the env contents.
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.
Thank you for your time in reviewing this!
I agree that the function is not creating a deep copy of the environment contents. However, in my tests, simply copying the pointer to the original environment was enough. know that inconsistencies in the data are possible, but I believe that ENV already has inconsistent behavior when used in simultaneous threads. Is there a case I missed that causes an error in the program?
Thanks again!
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.
Therefore ENV
isn't ractor-safe.
Before the ractor, GVL prevented it from the inconsistencies.
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.
Thank you. I will think about it some more.
It is important that the ENV object be accessible in Ractors. To make it Ractor-safe, its methods that get/set its values are now synchronized with this modification. This is done by placing a mutex around each of these methods. With this, the ENV object is now Ractor-safe and shareable. Additionally, tests are added to ensure that its behavior is correct in Ractors.