Problems with "shared"

jython234 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Oct 9 13:57:40 PDT 2016


Hello,

I've recently started a project in D, one which I plan to take 
advantage of concurrency. This means I will need to use the 
shared keyword. However, I have been having a few problems:

1. Where do I use the "shared" keyword? I've done things like 
making whole classes shared, which doesn't seem to make the 
member methods shared either. Also this creates a million 
compiler errors when I try to access the constructor from a 
non-shared function.

2. It seems that whenever I use shared I end up doing a ton of 
"unsafe" casts from shared, and to shared and it makes me feel 
uneasy. I don't think I'm supposed to be doing this.

3. Another concern I have is that I plan on using this project to 
introduce other people to D. These people will probably have some 
background with programming (such as Java), but will be new to 
the "systems" programming area. I like D because of how broad it 
can be, but one of the biggest problems it has is the "shared" 
issue with Thread local data. This could be hard for newcomers to 
learn.

Any tips on how I could fix these problems?


More information about the Digitalmars-d-learn mailing list