File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 6bd01d0ac804a5a839a4513907b5697e35c8ad2e
2
+ refs/heads/master: a3dd67ae9165ee87c98ba7e5585ce859fd3fbe68
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
5
5
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
Original file line number Diff line number Diff line change 5
5
//
6
6
// The filename is a song reference; google it in quotes.
7
7
8
- fn child_generation ( gens_left : uint ) {
8
+ fn child_generation( gens_left : uint , - c : pipes :: chan < ( ) > ) {
9
9
// This used to be O(n^2) in the number of generations that ever existed.
10
10
// With this code, only as many generations are alive at a time as tasks
11
11
// alive at a time,
12
+ let c = ~mut some ( c) ;
12
13
do task:: spawn_supervised {
14
+ let c = option : : swap_unwrap ( c) ;
13
15
if gens_left & 1 == 1 {
14
16
task:: yield ( ) ; // shake things up a bit
15
17
}
16
18
if gens_left > 0 {
17
- child_generation ( gens_left - 1 ) ; // recurse
19
+ child_generation ( gens_left - 1 , c) ; // recurse
20
+ } else {
21
+ c. send ( ( ) )
18
22
}
19
23
}
20
24
}
@@ -28,5 +32,9 @@ fn main(args: ~[~str]) {
28
32
copy args
29
33
} ;
30
34
31
- child_generation ( uint:: from_str ( args[ 1 ] ) . get ( ) ) ;
35
+ let ( c, p) = pipes:: stream ( ) ;
36
+ child_generation ( uint:: from_str ( args[ 1 ] ) . get ( ) , c) ;
37
+ if p. try_recv ( ) . is_none ( ) {
38
+ fail ~"it happened when we slumbered";
39
+ }
32
40
}
You can’t perform that action at this time.
0 commit comments