Skip to content

Commit 6c97924

Browse files
committed
threads
1 parent 7bd5e30 commit 6c97924

6 files changed

Lines changed: 37 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[workspace]
22
resolver = "3"
3-
members = ["basics","course", "guessgame", "intmut", "myutils"]
3+
members = ["basics","course", "guessgame", "intmut", "myutils", "paral"]

course/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ edition = "2024"
77
basics = { path = "../basics" }
88
myutils = { path = "../myutils" }
99
guessgame = { path = "../guessgame" }
10-
intmut = { path = "../intmut" }
10+
intmut = { path = "../intmut" }
11+
paral = { path = "../paral" }

course/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use basics;
22
use myutils::stuff;
33
use myutils::testing;
44
//use guessgame
5+
use paral;
56

67
fn main() {
78
basics::basics();
@@ -14,4 +15,5 @@ fn main() {
1415
//guessgame::guess_game();
1516
intmut::intmut();
1617
intmut::weakrefs();
18+
paral::threads();
1719
}

paral/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "paral"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]

paral/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use std::{thread, time::Duration};
2+
3+
pub fn threads() {
4+
println!("Threads");
5+
let handle = thread::spawn(|| {
6+
for i in 1..10 {
7+
println!("hi number {} from the spawned thread!", i);
8+
thread::sleep(Duration::from_millis(1));
9+
}
10+
});
11+
handle.join().unwrap();
12+
println!("Joined");
13+
14+
let v = vec![1, 2, 3];
15+
let handle = thread::spawn(move || {
16+
for i in 1..10 {
17+
println!("{}: Here's a vector: {:?}", i, v);
18+
}
19+
});
20+
handle.join().unwrap();
21+
}

0 commit comments

Comments
 (0)