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

What is the reason for using 2 seconds timeout in linux futex #3

Closed
ashtum opened this issue Apr 4, 2021 · 1 comment
Closed

What is the reason for using 2 seconds timeout in linux futex #3

ashtum opened this issue Apr 4, 2021 · 1 comment

Comments

@ashtum
Copy link

ashtum commented Apr 4, 2021

I can't understand the purpose of using 2 seconds timeout in linux futex syscall, What is the purpose of it?

constexpr timespec timeout = { 2, 0 }; // Hedge on rare 'int version' aliasing.

@ogiroux
Copy link
Owner

ogiroux commented Apr 4, 2021

There is a not-quite theoretical corner case where if the proxy integer overflowed at exactly the wrong time, in exactly the wrong conditions, it could cause this use of Futex to hang if there was no timeout.

In an alternate world where Futex works with 64-bit integers, there would be no need to ever worry about it, the computer would turn back into sand before the condition could occur. But since this world's Futex uses 32-bit integers and it takes ~seconds to wrap around this quantity, we do need to guard against it here.

This 2s time is chosen arbitrarily -- it bounds the apparent hiccup the application would experience (to 2s) in the extremely rare case, and it still suppresses polling to a very high degree (once every 2s is one-in-many-billions suppression). Users who need real-time control should not be using this path anyway, they should be using atomic_signed_lock_free instead, which does not go to a proxy integer like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants