We are going to create a train of 10 threads in this recipe and declare a vector where we will hold all the thread
handles. We will join the main thread
later to ensure the handles are executed and return the value that we would send while spawning the thread
. We will extensively use the concepts learned from the previous two recipes.
We will require the Rust compiler and any text editor for developing the Rust code snippet.
The following steps will walk you through this implementation:
- Create a file named
sample_thread_expt.rs
and open it in your text editor. - Write the code header with the relevant information:
//-- ######################### //-- Task: Spawning 10 threads in rust //-- Author: Vigneshwer.D //-- Version: 1.0.0 //-- Date: 19 March 17 //-- #########################
- Call the standard
thread
library using theuse
keyword and create astatic
variable calledNO_THREADS
using the 32...