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

gh-117657: Fix data races for set_inheritable in fileutils.c with free-threaded builds #120458

Closed
wants to merge 1 commit into from

Conversation

aisk
Copy link
Member

@aisk aisk commented Jun 13, 2024

ioctl_works in set_inheritable function is a static variable which has three possible values:

Value Meaning
-1 Initial value when the process starts.
0 ioctl cannot be used for this functionality; fcntl is used as a fallback.
1 ioctl works in the current environment, and we should continue to use it.

When it is 0, using ioctl as a fast path will always be skipped.

When it is -1 or 1, ioctl will be used as a fast path to perform the functionality, and it will be set to 0 or 1 based on the result of whether ioctl raises an error or not. And if ioctl failed, use fnctl as a slow path fallback.

Following this logic, it is safe to call set_inheritable with multiple threads in a free-threaded build. The fast path can be safely used even if it leads to failure. Therefore, we can simply use atomic operations to read or write ioctl_works's value to resolve data races.

@aisk
Copy link
Member Author

aisk commented Jun 13, 2024

Sorry, just noticed that this is duplicated with #120175.

@aisk aisk closed this Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant