On 05.12.2013 03:15, Bill Myers wrote:
The reason I introduced COW when RC > 1 is that it allows persistent data structures to be mutated in place if there aren't extra references, just like non-persistent data structures.
That's a great idea that an might obviate the need to have a separate `Builder` type (as in .Net [1]) or explicit `transients` (as in Clojure [2]).

However, one has to be careful to "lock" the whole path when working in a graph structure in a concurrent setting, so no other task/thread changes a node further up, while the first task does changes to the some node further down. This can happen, when relying on the reference count alone because there can be N Arc-references + M borrowed references to some memory box---and the reference count will only be N. Conceptually, the `get()` method in Arc also should increase the reference count for the lifetime of the borrowed reference. For safe memory management, this is not necessary because the compiler will ensure that no borrowed reference outlives all memory owners, but for counting who has access to the memory contents, the reference count alone is inadequate.

This should not be hard to mitigate manually but it's a potential source for some nasty race conditions ;)

-Michael

[1] https://msdn.microsoft.com/en-us/library/dn385366(v=vs.110).aspx
[2] http://clojure.org/transients
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to