-
Notifications
You must be signed in to change notification settings - Fork 150
Open
Description
I would like to propose implementing the Sync trait for the SerialPort trait. The primary blocker for this seems like COMPort does not automatically implement Sync due to the HANDLE type using a raw pointer. TTYPort already implements Sync because it uses RawFd which is simply a primitive type.
Upon investigation, I found the Rust standard library contains the following statement about Windows HANDLE types:
// The Windows [`HANDLE`] type may be transferred across and shared between
// thread boundaries (despite containing a `*mut void`, which in general isn't
// `Send` or `Sync`).
//
// [`HANDLE`]: std::os::windows::raw::HANDLE
#[stable(feature = "io_safety", since = "1.63.0")]
unsafe impl Send for OwnedHandle {}
// ...
#[stable(feature = "io_safety", since = "1.63.0")]
unsafe impl Sync for OwnedHandle {}Maybe we could do the same for the COMPort type by implementing the Sync trait similarly. This would allow SerialPort to also implement Sync, enabling usage in multi-threaded contexts. I believe this is sound because IO-related operations still require exclusive access to &mut Self to perform.
ethancreeger, ileon, aabizri, LateNightIceCream and mcobzarenco
Metadata
Metadata
Assignees
Labels
No labels