-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Sync channel returns RecvError #31
Comments
This could be fixed by extern crate coio;
extern crate env_logger;
use coio::Scheduler;
use coio::sync::mpsc;
fn main() {
env_logger::init().unwrap();
Scheduler::new().run(|| {
let (tx, rx) = mpsc::sync_channel(1);
let h = Scheduler::spawn(move|| {
// 2. Push 1 into the queue and push <main> into the work queue
tx.send(1).unwrap();
// 3. Force yield the current coroutine,
// which will let the receiver have a chance to be waken up and read data
Scheduler::sched();
});
// 1. The <main> coroutine block itself into the wait list
assert_eq!(rx.recv().unwrap(), 1);
h.join().unwrap();
}).unwrap();
} The official implementation of sync channel, the So when the last |
Ah good idea! I didn't think of this... I mean: I think it should still break if 2 different Processors are used. So... Should we really adopt the standard Rust channel semantics? Why are they even using this weird Disconnected state? Shouldn't a channel be empty before a Disconnected is returned? IMHO that would make a lot more sense... |
I spent some time on reading the source code of the official implementation of mpsc channel, and I think it too complicated to reinvent this wheel. The behavior should have been discussed in RFC, so I think it is Ok to use it. Also, you cannot reproduce it with threads. use std::thread;
use std::sync::mpsc;
fn main() {
let (tx, rx) = mpsc::sync_channel(1);
let t = thread::spawn(move|| {
tx.send(1).unwrap();
});
t.join().unwrap();
rx.recv().unwrap();
} It always works because the official implementation will actually park the thread. |
I've read it too now... |
Yep. I agree. |
Minimal test case:
The program would panic with message:
The text was updated successfully, but these errors were encountered: