COMP3007_Modern_Programming_Languages (5)
COMP3007_Modern_Programming_Languages (5)
Fall 2024-2025
1 Introduction to Concurrency
3 Using Threads
7 Async/Await
8 Conclusion
12 for i in 1..5 {
13 println !("hi number {} from the main thread !",
i);
14 thread :: sleep( Duration :: from_millis (1));
15 }
16 }
Dr. Öğr. Üyesi Yusuf Kürşat Tuncel (Department
COMP3007
of Computer
- Modern
Engineering)
Programming Languages Fall 2024-2025 10 / 22
Waiting for All Threads to Finish
3 fn main () {
4 let v = vec ![1, 2, 3];
5
6 let handle = thread :: spawn(move || {
7 println !("Here 's a vector : {:?}", v);
8 });
9
10 handle .join (). unwrap ();
11 }
The move keyword forces the closure to take ownership of the values
it uses