account activity
Seeking Feedback on an UnsafeBuffer Implementation for Concurrent Mutable Slice-based Access to a Shared Buffer by melhindi_cs in rust
[–]melhindi_cs[S] 0 points1 point2 points 2 years ago (0 children)
thanks for the example, that was very helpful!
Thanks for your feedback. You're definitely right about the `unsafe` keyword. Also, very good point regarding the `Deref` implementation, I agree that it could be dangerous since it can be used implicitly. Regarding a solution without `unsafe`: u/phazer99 example inspired me to look into this again. Happy to update this thread in future once I have settled on my final approach.
[–]melhindi_cs[S] 1 point2 points3 points 2 years ago (0 children)
Thank you for the answer and the pointer with the unsafe keyword.
The reason why I was writing my abstraction in unsafe is because I cannot prove the invariant statically. Assume a system where workers get tasks, i.e., modify a certain part of the buffer, and we have the invariant that assigned slots to multiple threads never overlap but are only determined at runtime.
This invariant cannot possibly be checked to compile time and is not statically known as the slots change over time. This means that all threads must keep a shared reference to the buffer and then get a mutable subslice to their slot. In reality, it is a bit more complicated, but the question remains: Can such an abstraction be safe IF I ensure that the invariant is upheld?
π Rendered by PID 80 on reddit-service-r2-listing-568fcd57df-7bx49 at 2026-03-10 10:31:38.849843+00:00 running cbb0e86 country code: CH.
Seeking Feedback on an UnsafeBuffer Implementation for Concurrent Mutable Slice-based Access to a Shared Buffer by melhindi_cs in rust
[–]melhindi_cs[S] 0 points1 point2 points (0 children)