Domanda

Is there any way to mark all objects __gshared with DMD? I am working on a game engine where pretty much everything needs to be shared between threads, and spamming __gshared or shared everywhere doesn't cut it.

For everyone wanting me not to do this: Critical sections will be minimal and reduced to checking if an enum is set to Loaded or not (mutexed of course). So concurrency won't gain me anything.

È stato utile?

Soluzione

you can put all the variables in a block and declare that shared

__gshared{
   SharedClass instance;
   //...
}

also note that all fields in a shared class or struct are shared

I should however note that this inconvenience is by design and an encouragement to restructure your data to minimize the shared stuff

Altri suggerimenti

__gshared tells garbage collector that resource is may be used within external code, so you will need manually alloc/dealloc it(and so you can access the same resource in any thread), shared on the other hand is for actual multi-thread sharing.

though i may be wrong on some details, the actual idea is that

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top