comparison 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
comparison
equal deleted inserted replaced
12:70ab6c2f7f6e 13:afac42f2b948
1 use std::sync::Arc;
2 use std::sync::atomic::{AtomicUsize, Ordering};
3 use std::thread;
4
5 pub fn maina() {
6 let spinlock = Arc::new(AtomicUsize::new(1));
7
8 let spinlock_clone = Arc::clone(&spinlock);
9 let thread = thread::spawn(move|| {
10 spinlock_clone.store(0, Ordering::SeqCst);
11 });
12
13 // Wait for the other thread to release the lock
14 while spinlock.load(Ordering::SeqCst) != 0 {}
15
16 if let Err(panic) = thread.join() {
17 println!("Thread had an error: {:?}", panic);
18 }
19 }