pcwalton / libui-rs

Rust bindings to the minimalist, native, cross-platform UI toolkit `libui`
Apache License 2.0
212 stars 17 forks source link

Make Control impl Send #9

Closed mitchhentges closed 6 years ago

mitchhentges commented 8 years ago

This will allow controls to be cloned and reused from other threads. I'm not sure how to make this Rust-y, though, because perhaps each Control needs some more guarantees before it can impl Send.

Either way, it's working for me locally, so maybe it's useful for all

mitchhentges commented 8 years ago

Oh, and I needed to base this off of #5 so that it would build locally. If this PR should be merged, it should happen after #5

CryZe commented 8 years ago

Are you sure they are thread safe though? As far as I know GDI+ is not thread safe (I'm not sure if libui uses that though), so just putting impl Send there without verifying if the OS APIs are thread safe seems bad.

mitchhentges commented 8 years ago

Hmm, I'm not 100% sure that it's thread safe, but it's a start. Right now, it's impossible to manipulate controls from other threads. Now, it appears to work with a dummy progress bar app: https://github.com/mitchhentges/libui-rs/blob/ecm-example/ui/examples/ecm-download.rs#L54

Maybe it's just thread safe if you use queue_main? I'm not sure.

So, if anything, I was hoping that this would start discussion on designing a safe way to use libui in a multithreaded environment.