changeset 5:e869e24e5613

thread test
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 12 Jan 2021 11:34:52 +0900
parents 3d23e8517403
children 6e7204a1ba99
files Cargo.toml guessing/src/main.rs src/t16thread/Cargo.toml src/t16thread/src/main.rs
diffstat 4 files changed, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Cargo.toml	Tue Jan 12 10:35:31 2021 +0900
+++ b/Cargo.toml	Tue Jan 12 11:34:52 2021 +0900
@@ -13,4 +13,5 @@
 members = [
    "guessing",
    "src/t01guessing",
+   "src/t16thread",
 ]
--- a/guessing/src/main.rs	Tue Jan 12 10:35:31 2021 +0900
+++ b/guessing/src/main.rs	Tue Jan 12 11:34:52 2021 +0900
@@ -14,8 +14,34 @@
 
     Some(1)
 }
+fn main3() {
+    let x = 4;
+
+    //fn equal_to_x(z: i32) -> bool {
+    //    z == x
+    //}
+    let equal_to_x = | z | z == x;
+
+    let y = 4;
+
+    assert!(equal_to_x(y));
+}
+fn main2() {
+    let x = 3 ; // vec![1, 2, 3];
+
+    let equal_to_x = move |z| z == x;
+
+    println!("can't use x here: {:?}", x);
+
+    let y = 3 ; // vec![1, 2, 3];
+
+    assert!(equal_to_x(y));
+}
+
 fn main() -> std::io::Result<()> {
     println!("Hello, guessing!");
     main1();
+    main2();
+    main3();
     Ok(())
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/t16thread/Cargo.toml	Tue Jan 12 11:34:52 2021 +0900
@@ -0,0 +1,9 @@
+[package]
+name = "t16thread"
+version = "0.1.0"
+authors = ["Shinji KONO <kono@ie.u-ryukyu.ac.jp>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/t16thread/src/main.rs	Tue Jan 12 11:34:52 2021 +0900
@@ -0,0 +1,16 @@
+use std::thread;
+use std::time::Duration;
+
+fn main() {
+    thread::spawn(|| {
+        for i in 1..10 {
+            println!("hi number {} from the spawned thread!", i);
+            thread::sleep(Duration::from_millis(1));
+        }
+    });
+
+    for i in 1..5 {
+        println!("hi number {} from the main thread!", i);
+        thread::sleep(Duration::from_millis(1));
+    }
+}
\ No newline at end of file