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.
This commit is contained in:
parent
6372915a78
commit
c22b22d7b1
@ -141,7 +141,7 @@ pub fn swap(&self, val: bool, order: Ordering) -> bool {
|
||||
///
|
||||
/// 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
|
||||
|
Loading…
Reference in New Issue
Block a user