pass-by-ref semantics for structs (was Deque impl.)

Steven Schveighoffer schveiguy at yahoo.com
Thu Jan 31 14:37:39 PST 2013


On Thu, 31 Jan 2013 17:31:38 -0500, Rainer Schuetze <r.sagitario at gmx.de>  
wrote:

> Any reference that is accessible from multiple threads, e.g. a global  
> shared variable.
>
> shared(Container) allObjects;
>
> Without any thread having a reference to it, the payload's reference  
> count is 1. The reading thread above increments the counter when making  
> a local copy, but the writing thread decrements the counter when  
> assigning Container.init. If both run concurrently, with the sequence 1  
> to 3 above, trouble is inevitable.

Right, but isn't that an issue with having ANY shared variable that isn't  
protected by a lock?

I was thinking you had passed the pointer in via a message or something.

-Steve


More information about the Digitalmars-d mailing list