shared - i need it to be useful

Steven Schveighoffer schveiguy at gmail.com
Thu Oct 18 19:18:47 UTC 2018


On 10/18/18 2:42 PM, Stanislav Blinov wrote:
> On Thursday, 18 October 2018 at 18:26:27 UTC, Steven Schveighoffer wrote:
>> On 10/18/18 1:47 PM, Stanislav Blinov wrote:
>>> On Thursday, 18 October 2018 at 17:17:37 UTC, Atila Neves wrote:
>>>> On Monday, 15 October 2018 at 18:46:45 UTC, Manu wrote:
>>>>> 1. shared should behave exactly like const, except in addition to 
>>>>> inhibiting write access, it also inhibits read access.
>>>>
>>>> How is this significantly different from now?
>>>>
>>>> -----------------
>>>> shared int i;
>>>> ++i;
>>>>
>>>> Error: read-modify-write operations are not allowed for shared 
>>>> variables. Use core.atomic.atomicOp!"+="(i, 1) instead.
>>>> -----------------
>>>>
>>>> There's not much one can do to modify a shared value as it is.
>>>
>>> i = 1;
>>> int x = i;
>>> shared int y = i;
>>
>> This should be fine, y is not shared when being created.
> 
> 'y' isn't, but 'i' is. It's fine on amd64, but that's incidental.

OH, I didn't even notice that `i` didn't have a type, so it was a 
continuation of the original example! I read it as declaring y as shared 
and assigning it to a thread-local (which it isn't actually).

My bad.

-Steve


More information about the Digitalmars-d mailing list