Mercurial > hg > Members > kono > rust-tutorial
changeset 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 | 70ab6c2f7f6e |
children | |
files | src/async_test/src/atomic_test.rs src/async_test/src/fu_test.rs src/async_test/src/lib.rs src/async_test/src/main.rs |
diffstat | 4 files changed, 25 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/async_test/src/atomic_test.rs Tue Jan 19 18:30:44 2021 +0900 @@ -0,0 +1,19 @@ +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); + } +} \ No newline at end of file
--- a/src/async_test/src/fu_test.rs Mon Jan 18 20:52:32 2021 +0900 +++ b/src/async_test/src/fu_test.rs Tue Jan 19 18:30:44 2021 +0900 @@ -37,8 +37,9 @@ } pub fn fu_test() { - let future = get_future(); + let future1 = get_future(); // ThreadPool::new(4).execute(future); block_on(future); + block_on(future1); } \ No newline at end of file
--- a/src/async_test/src/lib.rs Mon Jan 18 20:52:32 2021 +0900 +++ b/src/async_test/src/lib.rs Tue Jan 19 18:30:44 2021 +0900 @@ -1,2 +1,2 @@ -pub mod fu_test; \ No newline at end of file +pub mod fu_test;
--- a/src/async_test/src/main.rs Mon Jan 18 20:52:32 2021 +0900 +++ b/src/async_test/src/main.rs Tue Jan 19 18:30:44 2021 +0900 @@ -1,3 +1,5 @@ + +// from https://rust-lang.github.io/async-book/01_getting_started/04_async_await_primer.html use futures::executor::block_on; struct Song { @@ -37,6 +39,7 @@ fn main() { let m = async_main(); println!("waiting"); + // m.await; block_on(m); async_test::fu_test::fu_test(); } \ No newline at end of file