Skip to content

kernel_version can cause a data race when called from multiple threads #2028

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

Closed
LegionMammal978 opened this issue Apr 29, 2023 · 0 comments · Fixed by #2029
Closed

kernel_version can cause a data race when called from multiple threads #2028

LegionMammal978 opened this issue Apr 29, 2023 · 0 comments · Fixed by #2029

Comments

@LegionMammal978
Copy link

In src/features.rs, kernel_version() is defined as:

    fn kernel_version() -> Result<usize> {
        static mut KERNEL_VERS: usize = 0;

        unsafe {
            if KERNEL_VERS == 0 {
                KERNEL_VERS = parse_kernel_version()?;
            }

            Ok(KERNEL_VERS)
        }
    }

If two threads call this function simultaneously when KERNEL_VERS is still 0, then it will result in a data race. A trivial fix is to replace it with an AtomicUsize accessed with Relaxed, since the worst case is that a thread performs a redundant uname() call.

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

Successfully merging a pull request may close this issue.

1 participant