Skip to content

Commit

Permalink
fix(threads): require that references passed to a thread be 'static
Browse files Browse the repository at this point in the history
References passed to a thread must be valid for its entire lifetime.
  • Loading branch information
ROMemories committed Apr 16, 2024
1 parent fe11eeb commit 85080cf
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/riot-rs-threads/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub unsafe fn start_threading() {

/// Trait for types that fit into a single register.
///
/// Currently implemented for references (`&T`) and usize.
/// Currently implemented for static references (`&'static T`) and usize.
pub trait Arguable {
fn into_arg(self) -> usize;
}
Expand All @@ -212,7 +212,9 @@ impl Arguable for () {
}
}

impl<T> Arguable for &T {
/// [`Arguable`] is only implemented on *static* references because the references passed to a
/// thread must be valid for its entire lifetime.
impl<T> Arguable for &'static T {
fn into_arg(self) -> usize {
self as *const T as usize
}
Expand Down

0 comments on commit 85080cf

Please sign in to comment.