synchronized classes and shared

Loara loara at noreply.com
Fri Aug 19 19:43:09 UTC 2022


On Friday, 19 August 2022 at 13:49:00 UTC, frame wrote:
> An atomic operation is a hardware instruction, synchronization 
> is more or less software implemented. Very different things. So 
> D says using `shared` is preparation for atomic operations that 
> are considered more thread safe than any other mechanism and 
> only allows such operations on objects that have that storage 
> class, giving some guarantee if you are using it right (at 
> least this is my understanding of it).
>
> As synchronization needs a mutex, you would lose advantages of 
> atomic and/or doing something wrong, so it makes no big sense 
> to convert the code automatically or it could be an error too.

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`.




More information about the Digitalmars-d mailing list