Skip to content

Commit

Permalink
Mistake in AtomicBool spinlock example
Browse files Browse the repository at this point in the history
The current example of a spinlock was not correct. The lock is actually acquired
when old == result. So we only need to deschedule when this is not the case.
  • Loading branch information
mvdnes committed Jul 10, 2014
1 parent 6372915 commit c22b22d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libcore/atomics.rs
Expand Up @@ -141,7 +141,7 @@ impl AtomicBool {
///
/// fn with_lock(spinlock: &Arc<AtomicBool>, f: || -> ()) {
/// // CAS loop until we are able to replace `false` with `true`
/// while spinlock.compare_and_swap(false, true, SeqCst) == false {
/// while spinlock.compare_and_swap(false, true, SeqCst) != false {
/// // Since tasks may not be preemptive (if they are green threads)
/// // yield to the scheduler to let the other task run. Low level
/// // concurrent code needs to take into account Rust's two threading
Expand Down

5 comments on commit c22b22d

@bors
Copy link
Contributor

@bors bors commented on c22b22d Jul 11, 2014

Choose a reason for hiding this comment

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

saw approval from alexcrichton
at mvdnes@c22b22d

@bors
Copy link
Contributor

@bors bors commented on c22b22d Jul 11, 2014

Choose a reason for hiding this comment

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

merging mvdnes/rust/spinlock_error = c22b22d into auto

@bors
Copy link
Contributor

@bors bors commented on c22b22d Jul 11, 2014

Choose a reason for hiding this comment

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

mvdnes/rust/spinlock_error = c22b22d merged ok, testing candidate = ca56650

@bors
Copy link
Contributor

@bors bors commented on c22b22d Jul 11, 2014

Choose a reason for hiding this comment

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

fast-forwarding master to auto = ca56650

Please sign in to comment.