synchronized classes and shared

frame frame86 at live.com
Sat Aug 20 23:20:43 UTC 2022


On Friday, 19 August 2022 at 19:43:09 UTC, Loara wrote:

> Right, but then Phobos should allow to pass also `synchronized` 
> classes between threads and not only `shared` data. Actually 
> `synchronized` classes are almost useless since you can't pass 
> through threads without using low-level functions or using 
> `cast`.

I would say there is no way to detect for a phobos module if the 
object passed would be a synchronized one but I totally missed 
out the fact that the `synchronized` class methods becomes indeed 
`shared` ones even if you don't explict declare it.

You can't just create the object without cast or explicit 
declaration, as `A.__ctor()` becomes shared:

```d
A c      = new A();        // fails, no shared included
auto c   = new A();        // fails, shared is strictly required
shared c = new A();        // fails also, but I think it that one 
should work
shared c = new shared A(); // works
auto c   = new shared A(); // works, obviously
```

Conclusion:

You have to deal with the `shared` thing anyway.


More information about the Digitalmars-d mailing list