Skip to content

Implement a proc-macros threads creation #83

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Implement a proc-macros threads creation #83

wants to merge 1 commit into from

Conversation

d3zd3z
Copy link
Collaborator

@d3zd3z d3zd3z commented Apr 9, 2025

Replace how Zephyr threads are declared in Rust. Provides a proc-macro to make this fairly straightforward:

#[zephyr::thread(stack_size = MY_STACK_SIZE)]
fn my_thread(arg1: u32, arg2: MyType) { ... }

This function can then be called, and will return a ReadThread. This has methods for setting priority, and a start method, which returns a RunningThread, which has a join method. The thread can be respawned after it has exited.

The thread macro also accepts a pool_size = nnn parameter, which will create an array of threads, and can be started that many times.

@d3zd3z d3zd3z requested review from teburd and cfriedt April 9, 2025 16:47
Copy link
Collaborator

@teburd teburd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it

///
/// Will block until the thread has terminated.
///
/// TODO: Allow a timeout?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be smart to allow a timeout and return the integer result.

Copy link
Member

@cfriedt cfriedt Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, would it make more sense to do something similar to what std::thread does where we return a Result that can be either Ok or an Err? I guess that's more "rustonic" than integer return values 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think handling the timeout is a reasonable request. The Result will be Rust-y. But, thinly wrapped.

Allow an explicit timeout to be given to join, replacing the
implementation of the blocking one to one that calls it with a Forever
timeout.

Signed-off-by: David Brown <[email protected]>
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

Successfully merging this pull request may close these issues.

3 participants