shared - i need it to be useful

ag0aep6g anonymous at example.com
Wed Oct 17 20:58:12 UTC 2018


On 17.10.18 20:46, Manu wrote:
> struct NotThreadsafe
> {
>    int x;
>    void local()
>    {
>      ++x; // <- invalidates the method below, you violate the other
> function's `shared` promise
>    }
>    void notThreadsafe() shared
>    {
>      atomicIncrement(&x);
>    }
> }

In the `shared` method you'd get a nice error when attempting `++x;`, 
because it's not thread-safe. With your proposal, it's just as unsafe in 
`local`, but you don't get any help from the compiler in spotting it. 
`local` is effectively `@trusted` without being marked as such.


More information about the Digitalmars-d mailing list