{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/21851","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/21851/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/21851/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/21851/events","html_url":"https://github.com/rust-lang/rust/issues/21851","id":56183510,"number":21851,"title":"sync_channel(0) completely broken when used with Select","user":{"login":"mahkoh","id":1882250,"avatar_url":"https://avatars.githubusercontent.com/u/1882250?v=3","gravatar_id":"","url":"https://api.github.com/users/mahkoh","html_url":"https://github.com/mahkoh","followers_url":"https://api.github.com/users/mahkoh/followers","following_url":"https://api.github.com/users/mahkoh/following{/other_user}","gists_url":"https://api.github.com/users/mahkoh/gists{/gist_id}","starred_url":"https://api.github.com/users/mahkoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mahkoh/subscriptions","organizations_url":"https://api.github.com/users/mahkoh/orgs","repos_url":"https://api.github.com/users/mahkoh/repos","events_url":"https://api.github.com/users/mahkoh/events{/privacy}","received_events_url":"https://api.github.com/users/mahkoh/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-concurrency","name":"A-concurrency","color":"d7e102"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-libs","name":"A-libs","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-01T23:35:15Z","updated_at":"2015-04-08T21:59:03Z","closed_at":null,"body":"```rust\r\n#![feature(std_misc, io)]\r\n\r\nuse std::sync::mpsc::{sync_channel, Select};\r\nuse std::old_io::timer::{sleep};\r\nuse std::time::duration::{Duration};\r\nuse std::thread::{Thread};\r\n\r\nfn main() {\r\n    let (snd, rcv) = sync_channel(0);\r\n\r\n    Thread::spawn(move || {\r\n        if snd.send(0u8).is_ok() {\r\n            panic!();\r\n        }\r\n    });\r\n\r\n    let select = Select::new();\r\n\r\n    let mut handle = select.handle(&rcv);\r\n    unsafe { handle.add(); }\r\n\r\n    select.wait();\r\n\r\n    sleep(Duration::milliseconds(1));\r\n}\r\n```\r\n```\r\nthread '<unnamed>' panicked at 'explicit panic', test4.rs:13\r\n```\r\nAs you can see, `recv` is never called on `rcv`.\r\n\r\nThis 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."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/91048629","html_url":"https://github.com/rust-lang/rust/issues/21851#issuecomment-91048629","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/21851","id":91048629,"user":{"login":"LorenVS","id":528200,"avatar_url":"https://avatars.githubusercontent.com/u/528200?v=3","gravatar_id":"","url":"https://api.github.com/users/LorenVS","html_url":"https://github.com/LorenVS","followers_url":"https://api.github.com/users/LorenVS/followers","following_url":"https://api.github.com/users/LorenVS/following{/other_user}","gists_url":"https://api.github.com/users/LorenVS/gists{/gist_id}","starred_url":"https://api.github.com/users/LorenVS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LorenVS/subscriptions","organizations_url":"https://api.github.com/users/LorenVS/orgs","repos_url":"https://api.github.com/users/LorenVS/repos","events_url":"https://api.github.com/users/LorenVS/events{/privacy}","received_events_url":"https://api.github.com/users/LorenVS/received_events","type":"User","site_admin":false},"created_at":"2015-04-08T21:59:03Z","updated_at":"2015-04-08T21:59:03Z","body":"At an initial glance, this code looks like it should panic, and like that is the expected behavior. The send blocks until there is a corresponding receive call, which happens because of the select call. Once the send succeeds, a panic is forced.\r\n\r\nAm I missing something?"}}