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

stdio_usb input available callback can't call other stdio functions, and pico-examples iperf assumes it can. #474

Open
arg08 opened this issue Feb 24, 2024 · 3 comments

Comments

@arg08
Copy link

arg08 commented Feb 24, 2024

int key = getchar_timeout_us(0); // get any pending key press but don't wait

For stdio_usb, the callback registered with stdio_set_chars_available_callback() is called with the stdio_usb_mutex locked. This means that such callbacks can't call any other stdio functions (they attempt to claim the mutex and fail). In particular, this means you can't call getchar_timeout_ms() inside the callback.

This actually rather a dire limitation on the stdio callback mechanism, but that's how it is at the moment, and it means this piece of code in pico-examples doesn't work.

Fortunately, in this case the resolution is easy because it's already using async context: the stdio callback needs to do async_context_set_work_pending() unconditionally, and then key_pressed_worker_func() can read the key value and act on it accordingly.

@peterharperuk
Copy link
Contributor

Will be fixed by #461

@arg08
Copy link
Author

arg08 commented Feb 26, 2024

True it's really a stdio_usb bug, but here it could trivially be fixed to make the example work with the existing stdio_usb.

I've commented over on https://github.com/raspberrypi/pico-examples/issues/1603 with a suggested fix for the underlying issue.

(but I've just noticed you've closed 1603 which was "there's a bug", but left open 461 which is "must provide an example for this feature" where the commentary says that actually it's a bug!).

@peterharperuk
Copy link
Contributor

I've reopened it

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