Deprecate synchronized classes please!
IGotD-
nise at nise.com
Tue Sep 6 10:52:13 UTC 2022
On Tuesday, 6 September 2022 at 10:43:44 UTC, Loara wrote:
>
> You can't send a `synchronized` class to a different thread via
> `send` \ `receive` unless you make your class `shared`.
> Phobos's multithreading functions are focusing on `shared` data
> types at the expense of `synchronized` classes. There isn't any
> traits that tells you if a class is `synchronized` too.
>
I'm not sure you mean with "send". The point with with
synchronized classes is that you can use them everywhere, across
thread boundaries without ownership. If "send" is just a way to
share the synchronized class upon thread entry as a parameter,
then I'd say it's a bug and it should be rectified.
> Yes you can still use `synchronized` in you code, but in that
> case Phobos will go against you when you'll have to share your
> synchronized classes and force you to cast your classes and
> make your code less safe.
>
Yes, it's a gap in the inconsistent D design. D shared memory
model is broken in many ways.
> Also in a `synchronized` class each member becomes `shared`,
> but this will force you to use atomic operation even if you
> have exclusive access to data variables. All the stuff around
> `synchronized` seems poorly designed only as a copy of Java's
> synchronization and later abandoned.
If all members becomes atomic inside a synchronized class, then
it's a design error. The whole point of a synchronized class is
that the members should be normal variables and not atomics.
What is going on here?
More information about the Digitalmars-d
mailing list