Why do core.atomic functions require shared

Boris-Barboris ismailsiege at gmail.com
Wed Jul 4 09:25:27 UTC 2018


Given the pain of shared usage with std and pretty much every 
library in existence, I cowboyed the server without this 
qualifier. One of the mechanisms required atomic class reference 
compare-and-set, and the class reference is not shared, because 
it would otherwise require, like, 30 or 40 casts to non-shared in 
other places co compile. I was then mortified to learn that 
core.atomic operate on shared references\pointers\values, and 
that I had to do stuff like:
```
cas(cast(shared(C)*) &unshared_c, cast(shared C) unshared_c, 
cast(shared C) unshared_c);
atomicStore(*(cast(shared(C)*) &unshared_c), cast(shared(C)) 
unshared_c);
```

Does shared impose some alignment constraints in the backend, 
that are needed for core.atomic? Do these functions really need 
to work only with shared?

Side question: how hard is it for a semantic analysis to 
implicitly remove all shared qualifiers from all symbols 
referenced inside "synchronized" block (including "this" 
pointer). It would solve about 90% of my gripes with shared, I 
believe.


More information about the Digitalmars-d mailing list