[Issue 8295] Struct member destructor can not be called from shared struct instance

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 17 11:08:21 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=8295

--- Comment #10 from Marco Leise <Marco.Leise at gmx.de> ---
Thanks for the clarification. Shared has never been fully fleshed out. What we
can currently take away from the specification is this:

   "8.8 shared Attribute

   The shared attribute modifies the type from T to shared(T), the same way as
   const does."

My thinking is that top level qualifiers on assignments and function parameters
only have informative character. Sometimes we want to enforce a coding practice
that says that function parameters are no scratch space or make it easier to
reason about a piece of code by ensuring that variables cannot be modified
after the initial assignment. In any case these are copies of the values that
are assigned to them.
You can tell where I'm going: Copy a shared reference counting struct and it is
no longer shared except for the data it references. So in my brain there is no
"shared(RefCounter!T)" that atomically decrements the counter. For that I would
have to create another "SharedRefCounter". Whether or not the payload is shared
is independent of that.

I don't know what I can say about thread local allocators. You can still share
data allocated with them as long as upon destruction you queue the item in for
freeing on the correct thread's "items to be free'd list". It all has to be
manually implemented without help from the language.

--


More information about the Digitalmars-d-bugs mailing list