Temporally safe by default
Dukc
ajieskola at gmail.com
Fri Apr 5 10:24:23 UTC 2024
On Friday, 5 April 2024 at 09:59:58 UTC, Richard (Rikki) Andrew
Cattermole wrote:
> See all the examples of people having to cast on/off ``shared``
> to pass memory between threads.
That's what it's like if you try to share plain arrays. And
that's how it should be. Manipulating a shared data structure in
a temporally safe way is complicated, so to access `shared` data
it makes sense that do that you need to explicitly give up
temporal safety (cast) or do it the hard way (`core.atomic`).
But if you had the data structure struct, you wouldn't have to do
either. It would have a `shared` constructor and `shared` member
functions to manipulate all the data, all the ugly atomics and/or
casting getting done in the struct implementation. It'd let you
to copy part of itself to your thread local storage and inspect
there at your leisure. It'd let you lock part of itself for a
time when you wish to do an in-place update (during which the
data in question would be typed as thread-local and guarded
against escape with DIP1000). And so on.
More information about the dip.ideas
mailing list