thread_safety/
thread_safety.rs1use hackerlog::*;
2use std::thread;
3use std::time::Duration;
4
5fn main() {
6 logger().verbose(true);
8
9 let mut handles = vec![];
11
12 for i in 0..3 {
13 let handle = thread::spawn(move || {
14 let _ctx = logger().add_context("thread_id", i.to_string());
15
16 for j in 0..3 {
17 info!("Message {} from thread {}", j, i);
18 thread::sleep(Duration::from_millis(100));
19 }
20 });
21
22 handles.push(handle);
23 }
24
25 for handle in handles {
27 handle.join().unwrap();
28 }
29}