On Thu, 31 Jan 2013 17:37:39 -0500, Steven Schveighoffer
<[email protected]> wrote:
On Thu, 31 Jan 2013 17:31:38 -0500, Rainer Schuetze <[email protected]>
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.
BTW, couldn't we solve this with a function that increments the retain
count, and then returns a pointer to the object? Such a method would have
to be atomic on shared instances.
-Steve