Re: [PATCH 1/3] rust: Introduce irq module
From: Benno Lossin
Date: Fri Jul 26 2024 - 17:30:24 EST
On 26.07.24 23:21, Boqun Feng wrote:
> On Thu, Jul 25, 2024 at 06:27:50PM -0400, Lyude Paul wrote:
> [...]
>> +pub struct IrqDisabled<'a>(PhantomData<&'a ()>);
>
> I think you need to make this type !Send and !Sync (because you are
> going to make it Copy). Otherwise, you will be able to pass the irq
> disabled token to another thread on a different CPU which doesn't have
> irq disabled.
Oh yeah this is a good catch! (although it should not matter at the
moment, see the end of the note below)
Just a note: it is not because of making it Copy, this problem already
exists in the current implementation. One could have sent the reference
to a different thread using a "scoped spawn"-esque function [1]. IIRC we
currently do not have such a function, but it should be possible to
later add such a function. (and it is much more accurate to make this
type not be thread safe)
[1]: https://doc.rust-lang.org/std/thread/struct.Scope.html#method.spawn
---
Cheers,
Benno