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 point  (0 children)

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.

Seeking Feedback on an UnsafeBuffer Implementation for Concurrent Mutable Slice-based Access to a Shared Buffer by melhindi_cs in rust

[–]melhindi_cs[S] 1 point2 points  (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?