-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Implement flock_*
fiber-aware, without blocking the thread
#12728
Implement flock_*
fiber-aware, without blocking the thread
#12728
Conversation
(changes are requested for the |
raise IO::Error.from_errno("Error applying or removing file lock") | ||
if retry | ||
until flock(op) | ||
::Fiber.yield |
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.
If no other fibers have work to be done, what prevents this from spinning and using up 100% of the CPU until the file lock is obtained?
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.
Fair point. A sleep 5.milliseconds
will significantly lower the pressure on the CPU in such scenario without blocking for too long.
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.
Yeah that's definitely not ideal. This is just a basic first step and we're missing other features like a timeout (as suggested in #12721 (comment)). Timeout and sleep are related, so might make sense to consider that together.
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.
Do we know when the timeout feature will be available in the crystal release for this function?
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.
Actually, I'm not sure about the timeout. Maybe that should rather be handled more generically.
We should definitely sleep the fiber, though. I've posted a patch for that in #12861.
Resolves #12721