Skip to content

Commit e91abd1

Browse files
committed
---
yaml --- r: 8071 b: refs/heads/snap-stage3 c: cdb246f h: refs/heads/master i: 8069: a713c74 8067: 6a74b03 8063: 71d5518 v: v3
1 parent 700af9c commit e91abd1

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

[refs]

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

0 commit comments

Comments
 (0)