3 ms·
Even in the flat structure case, doesn't reference counting turn referencing an object into a synchronization point? For example if I try to use several threads
by fiddlerwoaroof 10y ago
Even in the flat structure case, doesn't reference counting turn referencing an object into a synchronization point? For example if I try to use several threads to make a million objects reference a single object, I'll have to lock every time I add a reference, reducing parallelism.
- openasocket 10y agoWell yes and no. In the multi-threaded case you'd use ARC (atomic reference count) pointers. These use atomic instructions to increment and decrement references, and are thus lock-free. There's still contention, but only on the data bus and the cache coherency protocol for the atomic instructions. Under contention, you're looking at latency for access less than 80-100ns. Of course, if all of these threads are accessing an object at once you're going to have contentions no matter what, unless all of the threads are read-only.
- kazinator 10y agoReference counting is a form of GC. It has nondeterministic delays. You don't know which dropref() operation will just decrement and which will finalize. Moreover, when refcounted objects finalize, they recursively drop the refs they hold. Of course, in some trivial cases it is obvious. But in those cases, you could use manual memory management. For instance, trivial case: making an object and then dropping it in the same scope.
- dllthomas 10y ago> Moreover, when refcounted objects finalize, they recursively drop the refs they hold. You can (at the cost of some additional complication) make this more deterministic by adding newly-dead objects to a "finalize this soon" queue and chewing through that when you have time (or on a different thread).