Skip to content

Ilooping senders starve other tasks #8827

Closed
@brson

Description

@brson
Contributor

Depending on number of threads and steal results this test case may livelock, and probably exhaust memory:

fn periodical(n: int) -> Port<bool> {
    let (port, chan) = stream();
    do spawn {
        println(fmt!("periodical %d - begin", n));
        loop {
            for _ in range(1, n) {
                println(fmt!("periodical %d - sending...", n));
                chan.send(false);
                println(fmt!("periodical %d - sent", n));
            }
            chan.send(true);
        }
    }
    return port;
}

fn integers() -> Port<int> {
    let (port, chan) = stream();
    do spawn {
        println("integers - begin");
        let mut i = 1;
        loop {
            chan.send(i);
            i = i + 1;
        }
    }
    return port;
}

fn main() {
    let ints = integers();
    let threes = periodical(3);
    let fives = periodical(5);
    for _ in range(1, 100) {
        match (ints.recv(), threes.recv(), fives.recv()) {
            (_, true, true) => println("FizzBuzz"),
            (_, true, false) => println("Fizz"),
            (_, false, true) => println("Buzz"),
            (i, false, false) => println(fmt!("%d", i))
        }
    }
}

Activity

alexcrichton

alexcrichton commented on Dec 23, 2013

@alexcrichton
Member

This appears to no longer be a problem. Even if all the prints are removed (which trigger task scheduling), this test completes.

Flagging as needstest.

added a commit that references this issue on Apr 28, 2014
35f295d
added a commit that references this issue on Apr 28, 2014

auto merge of #13811 : alexcrichton/rust/closed-issues, r=sfackler

7a19a82
added a commit that references this issue on May 21, 2022

Auto merge of rust-lang#8832 - Alexendoo:duplicate-mod, r=Manishearth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alexcrichton@brson

      Issue actions

        Ilooping senders starve other tasks · Issue #8827 · rust-lang/rust