D1.5 anyone?

Walter Bright newshound2 at digitalmars.com
Wed Apr 12 17:06:22 UTC 2023


On 4/12/2023 12:38 AM, Richard (Rikki) Andrew Cattermole wrote:
> On 12/04/2023 7:27 PM, Walter Bright wrote:
>> On 4/12/2023 12:11 AM, Richard (Rikki) Andrew Cattermole wrote:
>>> Unless proven otherwise, all memory is owned by the process not the thread 
>>> and therefore is the default.
>>
>> Let's see if I understand:
>>
>>      int abc(int* p);
>>
>>      int sum(int[] a)
>>      {
>>          int sum = 0;
>>          abc(&sum);
>>          for (int i = 0; i < a.length; ++i)
>>              sum += a[i];
>>          return sum;
>>      }
>>
>> Your position is that `i` and `sum` should be shared variables? What if 
>> `abc(&sum)` passes `&sum` to a concurrent thread?
> 
> No, you have that backwards.
> 
> In both of those cases its owned by the thread. With @safe they would be scope, 
> which is a partial implementation of 'owned by thread' checking.

Then I don't know what you mean by default being shared. And why would @safe 
influence this?


> A better example would be `a`. This is an argument, with an unknown memory 
> lifetime or ownership, that should be shared implicitly even if it was marked 
> scope.

Such implicit sharing means C semantics, where the compiler assumes that none of 
it is shared, and there are no protections and it's all up to the programmer to 
put in synchronization code where necessary.

You can actually do that now in D, just leave off the 'shared' annotations.


More information about the Digitalmars-d mailing list