Skip to content

Instantly share code, notes, and snippets.

@dulimarta
Last active January 27, 2020 02:21
Show Gist options
  • Save dulimarta/d652de3ed0dd7efd2bbe95f2a1ad1254 to your computer and use it in GitHub Desktop.
Save dulimarta/d652de3ed0dd7efd2bbe95f2a1ad1254 to your computer and use it in GitHub Desktop.
CS452 Lab04 - Sample 1 (Rust)
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()
)
}
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