From c22b22d7b136a0ba27e4c8b5c634d651169684a8 Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Thu, 10 Jul 2014 11:51:19 +0200 Subject: [PATCH] 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. --- src/libcore/atomics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/atomics.rs b/src/libcore/atomics.rs index 971799acc78..e022fa2c370 100644 --- a/src/libcore/atomics.rs +++ b/src/libcore/atomics.rs @@ -141,7 +141,7 @@ impl AtomicBool { /// /// fn with_lock(spinlock: &Arc, 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