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

What happens when the callback blocks? #60

Open
kangalio opened this issue Jun 23, 2020 · 2 comments
Open

What happens when the callback blocks? #60

kangalio opened this issue Jun 23, 2020 · 2 comments

Comments

@kangalio
Copy link

kangalio commented Jun 23, 2020

Hi, you've said that the callbacks passed to MiniInput::connect "will never be called concurrently with itself". Now I'm wondering; what happens when the callback takes, say, two seconds to complete? What happens with midi messages arriving in those 2 seconds?

Those midi messages can't be processed right away because the callback is busy, so I could imagine several things:

  • they get discarded
  • they get queued, and will be processed when the callback finishes
    • how long is the queue? What's the limit where messages will start to get dropped?
  • or something else entirely (panic?)
@Boddlnagg
Copy link
Owner

It's an excellent question what happens when the callback blocks!

In general it's a very bad idea to block in the callback, but I've never tried it, and it probably depends on the backend. Maybe you can just try what happens when you thread::sleep in the callback? (I will do it myself when I have time.)

We should definitely document that blocking is forbidden in the callback. But we should also make sure that there is no safety issue from violating the assumption that the callback is not called concurrently with itself (maybe that can actually happen? I don't know ...).

@kangalio
Copy link
Author

Alright, I experimented, and found the following:

On my configuration - Linux, ALSA - if the callback blocks, pending messages will get queued. Apart from the one message in processing, only up to 100 messages fit into that queue. If 101 or more messages arrive while the callback is blocking, all pending messages will be discarded, and midir will print "Error in handle_input: no input event from ALSA MIDI input buffer!" to stderr.

Tl;dr: up to 100 pending messages will get queued; anything beyond that and all messages will get discarded. In no case will midir panic.

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

2 participants