You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
497 B
24 lines
497 B
use std::thread; |
|
|
|
fn main() { |
|
let (mut tx, rx) = spmc::channel(); |
|
|
|
let mut handles = Vec::new(); |
|
for n in 0..5 { |
|
let rx = rx.clone(); |
|
handles.push(thread::spawn(move || { |
|
while let Ok(msg) = rx.recv() { |
|
// println!("Hello"); |
|
println!("worker {} recvd: {}", n, msg); |
|
} |
|
})); |
|
} |
|
|
|
for i in 0..15 { |
|
tx.send(i).unwrap(); |
|
} |
|
|
|
for handle in handles { |
|
handle.join().unwrap(); |
|
} |
|
}
|
|
|