Deprecate synchronized classes please!

Loara loara at noreply.com
Tue Sep 6 10:43:44 UTC 2022


On Tuesday, 6 September 2022 at 09:30:51 UTC, IGotD- wrote:
> The reason is that you cannot always rely on atomic operations 
> is because they are very difficult, no compiler can ensure it 
> and it is often not even possible. Therefore mutex are often 
> used and therefore synchronized has its place and should be the 
> most common way to share data structures.

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.

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.

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.


More information about the Digitalmars-d mailing list