use std::collections::HashMap;
use std::io::{prelude::*, ErrorKind};
use std::fs::{self, File};
+use std::{thread, time, sync};
use lib::*;
use word_utils::{first_word, second_word};
}
}
+fn test_threads() {
+ let t1 = thread::spawn(|| {
+ for i in 0..10 {
+ println!("hello #{} from thread", i);
+ thread::sleep(time::Duration::from_millis(1));
+ }
+ });
+
+ for i in 1..5 {
+ println!("hello #{} from main", i);
+ thread::sleep(time::Duration::from_millis(1));
+ }
+
+ t1.join().unwrap();
+
+ let (tx1, rx) = sync::mpsc::channel();
+ let tx2 = tx1.clone();
+
+ let sender1 = thread::spawn(move || {
+ for s in ["hey", "from", "sender", "one"] {
+ tx1.send(s).expect("failed to send");
+ thread::sleep(time::Duration::from_millis(100));
+ }
+ });
+
+ let sender2 = thread::spawn(move || {
+ for s in ["Servus", "von", "Produzent", "zwei"] {
+ tx2.send(s).expect("failed to send");
+ thread::sleep(time::Duration::from_millis(100));
+ }
+ });
+
+ for received in rx {
+ println!("received {} from mpsc", received);
+ }
+
+ sender1.join().unwrap();
+ sender2.join().unwrap();
+}
+
fn main() {
test_strings();
test_vectors();
test_generics();
test_closures();
test_iterators();
+ test_threads();
}