valid uses of shared

Steven Schveighoffer schveiguy at yahoo.com
Mon Jun 11 05:11:26 PDT 2012


On Mon, 11 Jun 2012 07:56:12 -0400, Artur Skawina <art.08.09 at gmail.com>  
wrote:

> On 06/11/12 12:35, Steven Schveighoffer wrote:

>> I wholly disagree.  In fact, keeping the full qualifier intact  
>> *enforces* incorrect code, because you are forcing shared semantics on  
>> literally unshared data.
>>
>> Never would this start ignoring shared on data that is truly shared.   
>> This is why I don't really get your argument.
>>
>> If you could perhaps explain with an example, it might be helpful.
>
> *The programmer* can then treat shared data just like unshared. Because  
> every
> load and every store will "magically" work. I'm afraid that after more  
> than
> two or three people touch the code, the chances of it being correct  
> would be
> less than 50%...
> The fact that you can not (or shouldn't be able to) mix shared and  
> unshared
> freely is one of the main advantages of shared-annotation.

If shared variables aren't doing the right thing with loads and stores,  
then we should fix that.

But leaving things "the way they are" doesn't fix any problems:

shared int x;

void main()
{
     auto y = x; // typeof(y) == shared(int)
     y += 5;
     x = y;
}

How is this any more "correct" than if y is int?

-Steve


More information about the Digitalmars-d mailing list