shared - i need it to be useful

Steven Schveighoffer schveiguy at gmail.com
Thu Oct 18 18:26:27 UTC 2018


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.

However, this still is allowed, and shouldn't be:

y = 5;

-Steve


More information about the Digitalmars-d mailing list