shared - i need it to be useful

Peter Alexander peter.alexander.au at gmail.com
Mon Oct 15 20:02:27 UTC 2018


On Monday, 15 October 2018 at 18:46:45 UTC, Manu wrote:
> Destroy...

What you describe sounds better than what we currently have.

I have at least two concerns:

1. A single producer, single consumer (SPSC) queue is necessarily 
shared, but is only safe if there is one writing thread and one 
reading thread. Is it ok if shared also requires user discipline 
and/or runtime checks to ensure correct usage?

2. In your scheme (as I understand), a struct composed entirely 
of atomics would be able to implement shared methods without any 
casts, but also be completely thread *unsafe*. Is this okay?

Example of #2:

struct TwoInts {
   Atomic!int x, y;

   void swap() shared {
     int z = x.load;
     x.store(y.load);
     y.store(z);
   }
}


More information about the Digitalmars-d mailing list