Skip to content

comm::peek hangs #2841

Closed
Closed
@jesse99

Description

@jesse99

Was able to get comm::peek to hang with 8+ tasks. This was on Mac 10.7.4 using a rust pulled on July 8, 2012.

Here is a test case:

// rustc --test multiple_tasks.rs && ./multiple_tasks
use std;

enum control_event
{
    dup_event(str, comm::chan<str>),
    close_event,
}

fn silly(n: uint) -> comm::chan<control_event>
{
    do task::spawn_listener
    |control_port: comm::port<control_event>|
    {
        io::println(#fmt["started task %?", n]);
        loop
        {
            libc::funcs::posix88::unistd::sleep(1);

            if comm::peek(control_port)
            {
                alt comm::recv(control_port)
                {
                    dup_event(data, data_ch)
                    {
                        io::println(#fmt["task %? received %?", n, data]);
                        comm::send(data_ch, data + data);
                    }
                    close_event
                    {
                        io::println(#fmt["exiting task %?", n]);
                        break;
                    }
                }
            }
        }
    }
}

#[test]
fn blah()
{
    let po = comm::port();
    let ch = comm::chan(po);

    // With under 8 this test passes.
    // With 8 and above the test hangs (last thing printed is "started task 7").
    // If prints are added to the loop in silly you can see that the tasks are running.
    let silly_channels = do vec::from_fn(8) |n| {silly(n)};

    for vec::each(silly_channels)
    |sc|
    {
        comm::send(sc, dup_event("hey", ch));
        assert comm::recv(po) == "heyhey";
    }

    for vec::each(silly_channels)
    |sc|
    {
        comm::send(sc, close_event);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions