How to do it...

The following steps will walk you through this implementation:

  1. Create a file named sample_move.rs and open it in your text editor.
  2. Write the code header with the relevant information:
        //-- #########################
//-- Task: Passing values to a thread in rust
//-- Author: Vigneshwer.D
//-- Version: 1.0.0
//-- Date: 19 March 17
//-- #########################
  1. Call the standard thread library using the use keyword:
        use std::thread;
  1. Define the main function and declare two variables: x and handle. Assign x with the integer value 1 and assign handle to the new thread, using the thread::spawn command. Here's the code for this:
        fn main() { 
let x = 1; let handle = thread::spawn(move || {(x)});

println!("{:?}", handle.join().unwrap());
}

You will get the following screenshot as an output upon successful execution of the code:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.42.134