Mercurial > hg > Members > kono > rust-tutorial
view src/async_test/src/atomic_test.rs @ 13:afac42f2b948 default tip
fix comment
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 19 Jan 2021 18:30:44 +0900 |
parents | |
children |
line wrap: on
line source
use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; use std::thread; pub fn maina() { let spinlock = Arc::new(AtomicUsize::new(1)); let spinlock_clone = Arc::clone(&spinlock); let thread = thread::spawn(move|| { spinlock_clone.store(0, Ordering::SeqCst); }); // Wait for the other thread to release the lock while spinlock.load(Ordering::SeqCst) != 0 {} if let Err(panic) = thread.join() { println!("Thread had an error: {:?}", panic); } }