"> <@davidcole1340:matrix.org..." <- > <@jamesmunns:beeper.com> Gotcha! Yeah - basically I'm not sure how to do it better than that in "safe" + "userspace" code, if that makes sense? > > You can definitely write unsafe code with a safe API to allow something like this, for example I wrote the `cmim` crate a while back to specifically do this: https://docs.rs/cmim/latest/cmim/ > > It *looks* like a mutex, but there's no actual expensive locking, instead it looks at which ISR vector is active, and only allows one ISR to access the data, or you can disable the ISR to "move out" of the mutex. > > I wouldn't recommend that crate anymore, it's kinda old, but maybe that demonstrates how you can use unsafe to say "look I know it works like X, so I can make a safe API around that" I'm writing a crate called `grounded` right now to make it easier to write these kind of unsafe data structures easier (and easier to avoid UB!), I added an issue for maybe reworking the idea behind cmim for the kind of use case you just mentioned: https://github.com/jamesmunns/grounded/issues/6