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

lock_api: Bug in example spinlock implementation #215

Closed
phil-opp opened this issue Feb 12, 2020 · 2 comments
Closed

lock_api: Bug in example spinlock implementation #215

phil-opp opened this issue Feb 12, 2020 · 2 comments

Comments

@phil-opp
Copy link

The example spinlock implementation in https://docs.rs/lock_api/0.3.3/lock_api/#example does not seem to be correct. The problem is the try_lock method:

fn try_lock(&self) -> bool {
    self.0.swap(true, Ordering::Acquire)
}

The documentation isn't explicit about this, but I assume that the function should return true if the lock was successfully acquired. The problem is that swap returns the previous value, so this function returns true only if the lock is already acquired. So I think it should be !self.0.swap(true, Ordering::Acquire) instead.

@Amanieu
Copy link
Owner

Amanieu commented Feb 12, 2020

This has already been fixed in master, see #207.

@phil-opp
Copy link
Author

Ah, I did not notice this, sorry the duplicate report! Maybe there should be a new crates.io release for this, given that it recommends a broken spinlock implementation?

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