Skip to content

Commit c22b22d

Browse files
committed
Mistake in AtomicBool spinlock example
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.
1 parent 6372915 commit c22b22d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libcore/atomics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl AtomicBool {
141141
///
142142
/// fn with_lock(spinlock: &Arc<AtomicBool>, f: || -> ()) {
143143
/// // CAS loop until we are able to replace `false` with `true`
144-
/// while spinlock.compare_and_swap(false, true, SeqCst) == false {
144+
/// while spinlock.compare_and_swap(false, true, SeqCst) != false {
145145
/// // Since tasks may not be preemptive (if they are green threads)
146146
/// // yield to the scheduler to let the other task run. Low level
147147
/// // concurrent code needs to take into account Rust's two threading

0 commit comments

Comments
 (0)