Skip to content

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 cfriedt and teburd April 9, 2025 16:47
Copy link

@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]>
@d3zd3z d3zd3z merged commit e64cadb into main May 7, 2025
4 checks passed
@d3zd3z d3zd3z deleted the proc-task branch May 7, 2025 15:30
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