Replies: 2 comments
-
Hey, thanks for reaching out! Yes, this would technically be the preferred way to resolve this particular instance. But it still requires delicate care with transmutation, possibly one of the most dangerous aspects of unsafe code. I deliberately did not use this approach in the blog post though, because it's limited to contiguous collections. So, for example, it cannot be used for matrix/tensor views (very important use case!), or certain more esoteric data structures. You're right that it's not There are quite a few other alternative ways to approach many of the things I did in the blog post, so I decided against mentioning the alternatives, as the blog post might read like a sequence of "but actually you could also ...". I've gotten quite a few mentions about this particular point though, so perhaps I should have mentioned it :-) |
Beta Was this translation helpful? Give feedback.
-
Very cool. (Thanks to This Week in Rust for pointing me to your post!) I don't have any immediate use for
Thanks, -kb |
Beta Was this translation helpful? Give feedback.
-
I couldn't find another topic, hope that this is an okay venue.
I think these are really interesting ideas, and I'm curious to see where this will go!
I had one thought reading the introduction of the example, where the non-ergonomics of using bare raw pointers are shown.
Another alternative to using raw pointers or a slice of
Mutex
es (orAtomic
s) would beUnsafeCell
- so sending a&[UnsafeCell<T>]
slice to each thread, and then usingUnsafeCell::get()
.As I'm writing this, I'm remembering that
UnsafeCell
also isn'tSync
/Send
- so in total, I'm assuming this would end up looking pretty similar to the raw pointer version.Still, it might be worth mentioning in the blog post.
Beta Was this translation helpful? Give feedback.
All reactions