Skip to content

Commit 42c4a59

Browse files
committed
---
yaml --- r: 14059 b: refs/heads/try c: b4e221b h: refs/heads/master i: 14057: 8fbc7f7 14055: 835601e v: v3
1 parent b9b91c7 commit 42c4a59

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 5d4b372902da7b3234e7386e9b86cd700b434377
5+
refs/heads/try: b4e221bf90ba33fc0b765dfb9f1e6961f194e57a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Based on threadring.erlang by Jira Isa
2+
use std;
3+
4+
const n_threads: int = 503;
5+
6+
fn start(+token: int) {
7+
import iter::*;
8+
9+
let p = comm::port();
10+
let ch = iter::foldl(bind int::range(2, n_threads + 1, _),
11+
comm::chan(p)) { |ch, i|
12+
// FIXME: Some twiddling because we don't have a standard
13+
// reverse range function yet
14+
let id = n_threads + 2 - i;
15+
let {to_child, _} = task::spawn_connected::<int, int> {|p, _ch|
16+
roundtrip(id, p, ch)
17+
};
18+
to_child
19+
};
20+
comm::send(ch, token);
21+
roundtrip(1, p, ch);
22+
}
23+
24+
fn roundtrip(id: int, p: comm::port<int>, ch: comm::chan<int>) {
25+
while (true) {
26+
alt comm::recv(p) {
27+
1 {
28+
std::io::println(#fmt("%d\n", id));
29+
ret;
30+
}
31+
token {
32+
#debug("%d %d", id, token);
33+
comm::send(ch, token - 1);
34+
if token <= n_threads {
35+
ret;
36+
}
37+
}
38+
}
39+
}
40+
}
41+
42+
fn main(args: [str]) {
43+
let token = if vec::len(args) < 2u {
44+
1000
45+
} else {
46+
int::from_str(args[1])
47+
};
48+
49+
start(token);
50+
}

0 commit comments

Comments
 (0)