Difference between __gshared and shared.

Dmitry Olshansky via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 8 05:50:54 PDT 2015


On 08-Jul-2015 15:39, wobbles wrote:
> On Wednesday, 8 July 2015 at 12:21:22 UTC, Jonathan M Davis wrote:
>> On Wednesday, 8 July 2015 at 11:02:19 UTC, Márcio Martins wrote:
>>> [...]
>
>
> Interesting, so the main pain of using shared is the requirement to cast
> away the shared whenever you want to work on the data in a synchronized
> block.
>
> Is there any links do you know to the old conversations on what
> solutions are there for this?
>
> My first thought is using the 'with' keyword.
> shared int mySharedInt;
> synchronised(mutexObj) with (mySharedInt){
>      // any references to mySharedInt in this block are implicitly
> converted to non-shared
> }

It's good convention but still convention - who guarantees that the 
right mutex was locked? The locking protocol is outside of the 
competence of the compiler.

However there are synchronized _class_-es that might play nice with 
shared b/c very access to them is guarded by built-in mutex.

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list