unique ownership + unlimited safe generational references
Evan Ovadia
verdagon at gmail.com
Sun Apr 3 02:45:45 UTC 2022
On Wednesday, 30 March 2022 at 11:23:37 UTC, Nick Treleaven wrote:
> On Wednesday, 30 March 2022 at 07:02:16 UTC, Ola Fosheim
> Grøstad wrote:
>> How does this work with multithreaded shared references?
>
> Vale doesn't allow sharing mutable data across threads. But if
> the assumption that most programs alias data (copying a
> pointer) more often than they access the data is correct, it
> seems thread-safe generational references would still be faster
> (at least naive RC vs naive GR). The cost of mutual-exclusion
> would be paid on any dereference check but there would be no
> cost on aliasing. (Also multiple dereferences of the same data
> may only need one check in some cases).
Vale author here, someone pointed me to this thread.
Your understanding is correct!
I'll add some details on improvements made since that original
article, which could help explain why this seemingly crazy scheme
might work well:
* If we want to, we can lock an object to prevent it from being
freed at runtime, which is a good call in some cases and can let
us skip a lot of generation checks:
https://verdagon.dev/blog/hybrid-generational-memory
* Our "region borrow checker" would allow us to skip most
generation checks, see
https://verdagon.dev/blog/zero-cost-refs-regions. It would also
apply to RC (the article was written with RC in mind, in fact).
* (This is just a suspicion) Adding `iso` objects, like Pony
does, could make the region borrow usable for more than just
mutexes and pure functions.
I recently discovered a function that, between those two
mechanisms, would actually have zero overhead:
https://verdagon.dev/blog/vale-7drl#the-good-parts
If D wants to use any of these ideas, just give me a holler!
Always happy to discuss.
More information about the Digitalmars-d
mailing list