On Tuesday, 18 July 2017 at 19:24:18 UTC, Jonathan M Davis wrote:
On Tuesday, July 18, 2017 18:06:56 Atila Neves via
Digitalmars-d wrote:
On Tuesday, 18 July 2017 at 15:03:07 UTC, Kagamin wrote:
> On Tuesday, 18 July 2017 at 11:47:37 UTC, Petar Kirov
>
> [ZombineDev] wrote:
>> I think Atila was talking about this one:
>> struct A
>> {
>>
>> ~this() {}
>>
>> }
>>
>> void main()
>> {
>>
>> auto a = A();
>> shared b = A();
>>
>> }
>
> This is strange. There's nothing that suggests that struct A
> and its destructor is thread-safe, yet compiler assumes it
> is.
Except for a programmer explicitly and manually calling the
destructor (in which case, don't), the destructor is only ever
called by one thread.
It could still be a problem if the struct has a member variable
that is a reference type, because then something else could
refer to that object, and if it's shared, then you would need
to protect it, and the operations that shared prevents should
still be prevented. For full-on value types, it should be a
non-issue though.
- Jonathan M Davis
Mmm, I guess so. As Marco pointed out, it's a similar problem
with immutable (because the compiler casts it away before calling
the destructor).
Although I dare say that anybody writing code that depends on
such locking and destruction when shared is unlikely to get it
right in the first place.
Atila