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

SerialStream is Send on Linux but not Windows #69

Open
doylep opened this issue Dec 14, 2023 · 3 comments
Open

SerialStream is Send on Linux but not Windows #69

doylep opened this issue Dec 14, 2023 · 3 comments

Comments

@doylep
Copy link

doylep commented Dec 14, 2023

A simple example compiles on Linux but fails on Windows:

use tokio;
use tokio_serial as serial;

#[tokio::main]
async fn main() {
    let builder = serial::new("example/port", 9600);

    if let Ok(stream) = serial::SerialStream::open(&builder) {
        tokio::spawn(async move {
            let _ = stream.writable().await;
        });
    }
}

This fails to compile on Windows with "*mut c_void cannot be shared between threads safely".

Perhaps this is a known limitation? I believe the cause is the difference in internal representation, and the additional "com" struct required for Windows systems. Is there a recommended workaround?

Thanks for your help! And apologies if this was already known.

@edisno
Copy link

edisno commented Feb 8, 2024

I have the same problem - it seemed to work before?

@doylep
Copy link
Author

doylep commented Feb 12, 2024

Looks like the line in question (line 67 in lib.rs) is 3 years old (commit a0c1cdd), so I imagine it's not a new issue. I only encountered the issue because I'm in the process of porting Linux code to Windows.

Was it working for you recently? Could be an issue caused upstream.

@ndusart
Copy link
Contributor

ndusart commented Feb 13, 2024

The issue stems for the usage of raw HANDLE type in serialport::COMPort which is a *mut c_void.

The Send constraint become a Sync constraint on the HANDLE. The issue is on the upstream and they should wrap the HANDLE in a wrapper that is Sync because windows HANDLE are safe to share.

Refer to this issue in winapi defining HANDLE: retep998/winapi-rs#396

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

No branches or pull requests

3 participants