File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use basics;
22use myutils:: stuff;
33use myutils:: testing;
44//use guessgame
5- use paral;
5+ use paral:: threads ;
66
77fn main ( ) {
88 basics:: basics ( ) ;
@@ -15,5 +15,5 @@ fn main() {
1515 //guessgame::guess_game();
1616 intmut:: intmut ( ) ;
1717 intmut:: weakrefs ( ) ;
18- paral :: threads ( ) ;
18+ threads :: demo ( ) ;
1919}
Original file line number Diff line number Diff line change 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- }
1+ pub mod threads;
Original file line number Diff line number Diff line change 1+ use std:: { thread, time:: Duration } ;
2+
3+ pub fn demo ( ) {
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+ }
You can’t perform that action at this time.
0 commit comments