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

Fix race condition in chown #11885

Merged
merged 2 commits into from
Mar 15, 2022

Conversation

didactic-drunk
Copy link
Contributor

Described in #9174

@Blacksmoke16 Blacksmoke16 added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:files labels Mar 12, 2022
@straight-shoota straight-shoota linked an issue Mar 12, 2022 that may be closed by this pull request
Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While at it, could you perhaps switch the then and else branches to avoid the negated condition?
It's fine to merge either way.

@didactic-drunk
Copy link
Contributor Author

I know this is extreme micro optimizing, but if's are assumed to be true by the CPU without additional hinting correct? So if x should contain the more likely branch making the current if better because follow_symlinks defaults to false.

If only there was a way to give hints to the compiler LIKELY/UNLIKELY, or possibly use unless as a CPU hinted not likely branch.

@straight-shoota
Copy link
Member

I believe branch prediction is pretty useless at this point. On the odd chance this code ends up in a hot path, it won't make a difference when the next instruction is a costly syscall anyways.

@beta-ziliani beta-ziliani added this to the 1.4.0 milestone Mar 13, 2022
@straight-shoota straight-shoota merged commit 4140116 into crystal-lang:master Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File.chown race condition
5 participants