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

unsure how to use UI::queue_main with multiple threads #55

Open
Treeki opened this issue Dec 21, 2018 · 3 comments
Open

unsure how to use UI::queue_main with multiple threads #55

Treeki opened this issue Dec 21, 2018 · 3 comments
Labels
c-enhancement New feature or request p-medium Medium Priority x-good first issue Good for newcomers
Milestone

Comments

@Treeki
Copy link

Treeki commented Dec 21, 2018

Hey there,

I'm experimenting with iui as a new Rust programmer and I'm unsure whether I've hit upon a design issue with UI::queue_main, or if there's a solution I've just missed, as this method isn't used in any of the examples.

According to the iui documentation, UI::queue_main will queue a function to execute on the GUI thread - I assume this is the thread that called UI::init().

libui explicitly states you can call uiQueueMain from any thread, but I can't figure out how to do this with iui; it requires a UI instance which I cannot obtain in non-GUI threads as UI is neither Send nor Sync.

Is there a way to do this, or is this a bug/design flaw? Any advice would be appreciated!


For reference - I'm trying to offload ongoing USB device I/O using hidapi-rs onto a background thread and have it notify the GUI thread when data comes in or when the device is connected/disconnected.

The only method I can figure out for doing this is to have the GUI create a channel where the Sender is moved into the background thread and Reciever::try_recv is called regularly on a timer, but this feels inelegant to me and I'd much rather be able to have the background thread notify the GUI through libui's queuing mechanism so that it can update immediately.

@NoraCodes NoraCodes added c-enhancement New feature or request x-good first issue Good for newcomers p-medium Medium Priority labels Feb 23, 2019
@NoraCodes
Copy link
Collaborator

libui explicitly states you can call uiQueueMain from any thread

This is problem on our side, then, for sure. I think an API whereby we hand out a queuing token which is Send from UI and then provide queue_main on that token is the way to go here.

@NoraCodes NoraCodes added this to the 0.5 Release milestone Feb 26, 2019
@quickdudley
Copy link

queue_main doesn't actually use the self argument.

@quickdudley
Copy link

I have a branch at https://github.com/quickdudley/libui-rs/tree/55-async-queue-main which might address this; but I'm still figuring out how to test it. Will submit a pull request if I can do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-enhancement New feature or request p-medium Medium Priority x-good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants