Skip to content

Commit 95c4bce

Browse files
committed
---
yaml --- r: 142590 b: refs/heads/try2 c: 053b38e h: refs/heads/master v: v3
1 parent fbdfa4a commit 95c4bce

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 8eb358bb00f161f9e289de6cad8cfecc4c6eb681
8+
refs/heads/try2: 053b38e7e1cba8f7bb649a5fc8d82b0448d33c55
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/rt/sched.rs

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ pub impl Scheduler {
131131

132132
let mut self_sched = self;
133133

134+
// Always run through the scheduler loop at least once so that
135+
// we enter the sleep state and can then be woken up by other
136+
// schedulers.
137+
self_sched.event_loop.callback(Scheduler::run_sched_once);
138+
134139
unsafe {
135140
let event_loop: *mut ~EventLoopObject = {
136141
let event_loop: *mut ~EventLoopObject = &mut self_sched.event_loop;
@@ -258,7 +263,7 @@ pub impl Scheduler {
258263
let mut handle = handle;
259264
handle.send(Wake);
260265
}
261-
None => (/* pass */)
266+
None => break
262267
}
263268
}
264269
}
@@ -781,4 +786,63 @@ mod test {
781786
}
782787
}
783788
}
789+
790+
#[test]
791+
fn thread_ring() {
792+
use rt::comm::*;
793+
use iter::Times;
794+
use vec::OwnedVector;
795+
use container::Container;
796+
use comm::{GenericPort, GenericChan};
797+
798+
do run_in_mt_newsched_task {
799+
let (end_port, end_chan) = oneshot();
800+
801+
let n_tasks = 10;
802+
let token = 2000;
803+
804+
let mut (p, ch1) = stream();
805+
ch1.send((token, end_chan));
806+
let mut i = 2;
807+
while i <= n_tasks {
808+
let (next_p, ch) = stream();
809+
let imm_i = i;
810+
let imm_p = p;
811+
do spawntask_random {
812+
roundtrip(imm_i, n_tasks, &imm_p, &ch);
813+
};
814+
p = next_p;
815+
i += 1;
816+
}
817+
let imm_p = p;
818+
let imm_ch = ch1;
819+
do spawntask_random {
820+
roundtrip(1, n_tasks, &imm_p, &imm_ch);
821+
}
822+
823+
end_port.recv();
824+
}
825+
826+
fn roundtrip(id: int, n_tasks: int,
827+
p: &Port<(int, ChanOne<()>)>, ch: &Chan<(int, ChanOne<()>)>) {
828+
while (true) {
829+
match p.recv() {
830+
(1, end_chan) => {
831+
debug!("%d\n", id);
832+
end_chan.send(());
833+
return;
834+
}
835+
(token, end_chan) => {
836+
debug!("thread: %d got token: %d", id, token);
837+
ch.send((token - 1, end_chan));
838+
if token <= n_tasks {
839+
return;
840+
}
841+
}
842+
}
843+
}
844+
}
845+
846+
}
847+
784848
}

branches/try2/src/libstd/rt/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
6666
let f_cell = Cell(f);
6767

6868
do run_in_bare_thread {
69-
static N: uint = 2;
69+
static N: uint = 4;
7070

7171
let sleepers = SleeperList::new();
7272
let work_queue = WorkQueue::new();

0 commit comments

Comments
 (0)