Skip to content

sync_channel(0) completely broken when used with Select #21851

@mahkoh

Description

@mahkoh
#![feature(std_misc, io)]

use std::sync::mpsc::{sync_channel, Select};
use std::old_io::timer::{sleep};
use std::time::duration::{Duration};
use std::thread::{Thread};

fn main() {
    let (snd, rcv) = sync_channel(0);

    Thread::spawn(move || {
        if snd.send(0u8).is_ok() {
            panic!();
        }
    });

    let select = Select::new();

    let mut handle = select.handle(&rcv);
    unsafe { handle.add(); }

    select.wait();

    sleep(Duration::milliseconds(1));
}
thread '<unnamed>' panicked at 'explicit panic', test4.rs:13

As you can see, recv is never called on rcv.

This panics because send checks if there is someone sleeping on the "notification" condvar in a BlockedReceiver variant. Select::wait adds such a variant to get notified when there is a sender.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions