Last active
January 27, 2020 02:21
-
-
Save dulimarta/d652de3ed0dd7efd2bbe95f2a1ad1254 to your computer and use it in GitHub Desktop.
CS452 Lab04 - Sample 1 (Rust)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use nix::unistd::sleep; | |
use std::process; | |
use std::thread; | |
fn main() { | |
println!( | |
"From PID {} thread id {:?}", | |
process::id(), | |
thread::current().id() | |
); | |
thread::spawn(do_greeting); // Panic if failed to create thread | |
} | |
fn do_greeting() { | |
sleep(1); | |
println!( | |
"Thread version of Hello, world. PID={} TID={:?}", | |
process::id(), | |
thread::current().id() | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use nix::unistd::sleep; | |
use std::{process, thread}; | |
fn main() { | |
let thread_builder = thread::Builder::new(); | |
println!( | |
"From PID {} thread id {:?}", | |
process::id(), | |
thread::current().id() | |
); | |
thread_builder | |
.spawn(do_greeting) | |
.expect("Unable to create thread"); | |
sleep(2); | |
} | |
fn do_greeting() { | |
sleep(1); | |
println!( | |
"Thread version of Hello, world. PID={} TID={:?}", | |
process::id(), | |
thread::current().id() | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment