Skip to content
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

serial::windows::com::COMPort does not implement Send trait #16

Closed
apoloval opened this issue May 4, 2016 · 4 comments · Fixed by #17
Closed

serial::windows::com::COMPort does not implement Send trait #16

apoloval opened this issue May 4, 2016 · 4 comments · Fixed by #17

Comments

@apoloval
Copy link
Contributor

apoloval commented May 4, 2016

I'm writing an application using serial-rs, and I've found an obstacle trying to use it in a multithreading context.

The point is that I'm make a sort of serial port scanner. A listener thread will scan serial ports until a new device is connected. Then it creates a new thread and passes the SerialPort instance to it using move semantics.

In order to do that, SerialPort implementations must implement Send trait. The native implementation for Windows, serial::windows::com::COMPort if I'm not wrong, does not according to the following compilation error:

src\port\serial.rs:43:9: 43:18 error: the trait `core::marker::Send` is not implemented for the type `*mut *mut libc::c_void` [E0277]
src\port\serial.rs:43         Self::new(domain, proto::oacsp())
                              ^~~~~~~~~
src\port\serial.rs:43:9: 43:18 help: run `rustc --explain E0277` to see a detailed explanation
src\port\serial.rs:43:9: 43:18 note: `*mut *mut libc::c_void` cannot be sent between threads safely
src\port\serial.rs:43:9: 43:18 note: required because it appears within the type `serial::windows::com::COMPort`
src\port\serial.rs:43:9: 43:18 note: required because it appears within the type `proto::oacsp::output::MessageConsumer<serial::windows::com::COMPort>`
src\port\serial.rs:43:9: 43:18 note: required because it appears within the type `proto::oacsp::writer::EventWriter<proto::oacsp::output::MessageConsumer<serial::windows::com::COMPort>>`
src\port\serial.rs:43:9: 43:18 note: required by `port::serial::SerialPort::new` 

Moving the SerialPort instance from one thread to another should not be forbidden. Sharing it perhaps should not. Thus, Send + 'static should be implemented but Sync should not.

@dcuddeback
Copy link
Owner

@apoloval Thanks for catching this. I merged your PR that fixes this for Windows. Did you happen to try your serial port scanner on Unix as well?

@apoloval
Copy link
Contributor Author

No, I didn't. But I guess there should be no problem. In Unix, file descriptors are integer values, which are Send by default in Rust. In Windows, resource handles are pointers, which are not Send.

@dcuddeback
Copy link
Owner

@apoloval No worries. I came to the same conclusion. Just thought I'd check.

@dcuddeback
Copy link
Owner

I wrote something quick to verify that it works on Unix. Looks okay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants