Want reasonable reference counting? Disable automatic sharing of immutable
Steven Schveighoffer
schveiguy at gmail.com
Fri Nov 12 19:16:33 UTC 2021
On 11/12/21 12:46 PM, deadalnix wrote:
> I really don't think this makes sense.
>
> Providing people with tool to work on multiple cores (and we are
> aggressively moving toward heterogeneous compute, so it's getting worse).
`shared(immutable)` is fine for such a task. You only need to atomically
load any `__mutable` pieces inside.
having immutable implicitly shared is stupid when it's obviously not.
Like an immutable stack variable, why should I have to worry about
sharability there? Should I even be able to share it with another
thread, as the stack is easily destroyed?
> On the other hand, atomic are becoming cheaper and cheaper with each
> generation of pretty much every platforms. This is mostly due to the
> fact most machines now do regular loads/stores optimistically and
> speculate from there, just like they do for branch predictions. If it
> turns out there was contention then they rewind and revert back to do it
> in a more expensive fashion.
Removing implicit sharing from immutable doesn't change what shared
immutable means, or affect the performance of it, it just means you need
to be explicit about sharing.
-Steve
More information about the Digitalmars-d
mailing list