summary refs log tree commit diff
path: root/src/test/run-pass/platform_thread.rs
blob: 1878dd4618730d93d762fc941f926f506a9f023d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Jump back and forth between the OS main thread and a new scheduler.
// The OS main scheduler should continue to be available and not terminate
// while it is not in use.

fn main() {
    run(100);
}

fn run(i: int) {

    log(debug, i);

    if i == 0 {
        return;
    }

    do task::task().sched_mode(task::PlatformThread).unlinked().spawn {
        task::yield();
        do task::task().sched_mode(task::SingleThreaded).unlinked().spawn {
            task::yield();
            run(i - 1);
            task::yield();
        }
        task::yield();
    }
}