synchronized classes and shared
Loara
loara at noreply.com
Wed Aug 17 21:49:11 UTC 2022
When dealing with `shared` variables according to the official
documentation only atomic operations are allowed on them. But
since `synchronized` classes can be accessed only by one thread
at time it's reasonable to allow accessing its members even
inside `shared` context, indeed the compiler allows it at least
for small codes like the following:
```d
synchronized class A{
private:
int a;
public:
this() {
a = 1;
}
int getA() pure{
return a;
}
}
int main(){
shared A c = new A();
writeln(c.getA());
return 0;
}
```
So I ask why was this feature not added in the official
documentation?
More information about the Digitalmars-d
mailing list