Last change
on this file since 83b2fb5e was
7bef8cf,
checked in by Peter A. Buhr <pabuhr@…>, 18 months ago
|
start paper on llheap
|
-
Property mode set to
100644
|
File size:
739 bytes
|
Line | |
---|
1 | #![feature(async_await)] |
---|
2 | |
---|
3 | use std::thread; |
---|
4 | use std::sync::mpsc; |
---|
5 | |
---|
6 | fn main() { |
---|
7 | let (tx1, rx1) = mpsc::channel(); |
---|
8 | let (tx2, rx2) = mpsc::channel(); |
---|
9 | let (tx3, rx3) = mpsc::channel(); |
---|
10 | let (tx4, rx4) = mpsc::channel(); |
---|
11 | struct Msg { i : i64, j : i64 } |
---|
12 | let th = thread::spawn( || { |
---|
13 | let i : i64; let f : f64; let m : Msg; |
---|
14 | loop { |
---|
15 | select! { |
---|
16 | i = rx1.recv() => println( i ); |
---|
17 | f = rx2.recv() => println( f ); |
---|
18 | m = rx3.recv() => println( m ); |
---|
19 | _ = rx4.recv() => break; |
---|
20 | } |
---|
21 | } |
---|
22 | }); |
---|
23 | |
---|
24 | tx1.send( 0 ); // different messages |
---|
25 | tx2.send( 2.5 ); |
---|
26 | tx3.send( Msg { i:1, j:2 } ); |
---|
27 | tx4.send( "done" ); |
---|
28 | th.join().unwrap(); |
---|
29 | } |
---|
30 | |
---|
31 | // Local Variables: // |
---|
32 | // tab-width: 4 // |
---|
33 | // compile-command: "rustc -C opt-level=3 channels.rs" // |
---|
34 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.