On 2015-02-23 22:15:46 +0000, Walter Bright said:

int* count;

[...] if (count && --*count == 0) [...]

Careful!

This isn't memory safe and you have to thank the GC for it. If you ever use RCArray as a member variable in a class, the RCArray destructor is going to be called from a random thread when the class destructor is run. If some thread has a stack reference to the array you have a race.

You have to use an atomic counter unless you can prove the RCArray struct will never be put in a GC-managed context. It is rather sad that the language has no way to enforce such a restriction, and also that @safe cannot detect that this is a problem here.

--
Michel Fortin
[email protected]
http://michelf.com/

Reply via email to