Difference between __gshared and shared.
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jul 8 07:00:41 PDT 2015
On Wednesday, 8 July 2015 at 13:26:53 UTC, Shachar Shemesh wrote:
> On 08/07/15 15:08, Jonathan M Davis wrote:
>> I know that there are a number of people who get frustrated
>> with shared
>> and using __gshared instead, but unless you fully understand
>> what you're
>> doing and how the language works, and you're _really_ careful,
>> you're
>> going to shoot yourself in the foot it subtle ways if you do
>> that.
>>
> I guess my main issue with this statement is that I don't see
> how that is not the case when using shared.
Because unless you cast away shared, you're prevented from doing
much of anything to the object, and the compiler clearly
indicates which objects are shared, so the code that has to worry
about getting locks right and dealing with casting away shared
correctly is clearly marked and segregated from the rest of the
program, unlike with a language like C++ or Java where
_everything_ is shared, and you have no idea which objects are
actually shared across threads and which are thread-local.
What we have is uglier than we'd like, but that ugliness
highlights the small portion of code where you actually have to
deal with synchronization and threading issues so that if you do
have a problem with it, you have a very small amount of code to
dig through to figure out how you screwed it up.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list