valid uses of shared

Christophe Travert travert at
Mon Jun 18 05:48:00 PDT 2012

"Steven Schveighoffer" , dans le message (digitalmars.D:169568), a
 écrit :
> On Thu, 07 Jun 2012 22:16:21 -0400, Robert DaSilva <spunit262 at>  
> wrote:
>> You're forgetting about Global data.
> I wasn't so much forgetting it as I was ignoring it :)
> My thought on that is that the shared keyword in that case is truly a  
> storage class.  It's the one place where having a value-type based shared  
> value makes sense.  If we had some kind of synchronized/shared pairing,  
> the compiler would have to allocate mutex space for that too.
>> I think rather the head shared should be striped as this fits better  
>> with how D treats meaningless specifiers.
> I don't think we can do that with type constructors, but I'm not sure.   
> I'm certainly against it, as I am against the current abuses of that  
> methodology.
>> And trying to put structs that contain shared data on the stack should  
>> be illegal.

The compiler can already heap-allocate function variables that should be 
on the stack. So why disallowing shared for function variables?

void foo()
  shared int test; // allocates test on shared memory block.

Just like:
int delegate(int) adder(int a)
  return b => (a+b); // allocates a on the heap to make a closure.


More information about the Digitalmars-d mailing list