On Thursday, 20 July 2017 at 10:15:26 UTC, Kagamin wrote:
On Wednesday, 19 July 2017 at 20:59:03 UTC, Atila Neves wrote:
Not necessarily - the reference counted smart pointer doesn't
have to be `shared` itself to have a `shared` payload.
Yes, but it can be done either way. It's actually what Jack is
trying to do: make stdout shared and reference counted:
https://issues.dlang.org/show_bug.cgi?id=15768#c7
I'm not even entirely sure what the advantage of it being
`shared` would be, or even what that would really mean.
It will be thread safe and its lifetime will be automatically
managed.
You've definitely made me wonder about complicated cases, but
I'd argue that they'd be rare. Destructors are (bar manually
calling them) run in one thread. I'm having trouble imagining
a situation where two threads have references to a `shared`
object/value that is going to be destroyed deterministically.
A mutex, a file, a socket, any shareable resource. Though I
agree that reference counting of shared resources should be
optimized by thread local counters.
Mutexes and sockets are classes, so not destroyed
deterministically.
Anything that is `shared` is likely to be a reference (pointer,
class...), or a global. Either way the compiler-generated
destructor call isn't going to exist, which means it's probably
ok to cast away shared when the compiler inserts the automatic
call to a destructor at the end of scope.
Atila