File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ use std;
2
+ import std:: comm;
3
+ import std:: task;
4
+ import std:: uint;
5
+
6
+ fn child ( c : comm:: chan < ~uint > , i : uint ) {
7
+ comm:: send ( c, ~i) ;
8
+ }
9
+
10
+ fn main ( ) {
11
+ let p = comm:: port ( ) ;
12
+ let n = 100 u;
13
+ let expected = 0 u;
14
+ for each i in uint:: range ( 0 u, n) {
15
+ let f = bind child ( comm:: chan ( p) , i) ;
16
+ task:: spawn ( f) ;
17
+ expected += i;
18
+ }
19
+
20
+ let actual = 0 u;
21
+ for each i in uint:: range ( 0 u, n) {
22
+ let j = comm:: recv ( p) ;
23
+ actual += * j;
24
+ }
25
+
26
+ assert expected == actual;
27
+ }
Original file line number Diff line number Diff line change
1
+ use std;
2
+ import std:: comm;
3
+ import std:: task;
4
+
5
+ fn main ( ) {
6
+ let p = comm:: port ( ) ;
7
+ let c = comm:: chan ( p) ;
8
+ comm:: send ( c, ~100 ) ;
9
+ let v = comm:: recv ( p) ;
10
+ assert v == ~100 ;
11
+ }
You can’t perform that action at this time.
0 commit comments