4 ms·
Did you know that the counter is stored in a different place than the pointer? All current atomic<shared_ptr> implementations use a lock. Stack overflow is not
by pebal 4y ago
Did you know that the counter is stored in a different place than the pointer? All current atomic<shared_ptr> implementations use a lock. Stack overflow is not unique to a shared_ptr, but GC pointers don't have this problem. The reference counting has advantages, but it cannot fully replace GC pointers.
- CyberDildonics 4y agoI think you're confusing shared_ptr with reference counting as a technique in general. Can you answer the questions I have above without talking about shared_ptr? Stack overflow is not unique to a shared_ptr, but GC pointers don't have this problem No one should ever have this problem. It is a ridiculous way to make a linked list in the first place.
- pebal 4y agoI see you just don't want to see the problem. Look at this document: https://www.open-std.org/jtc1/sc22/WG21/docs/papers/2014/n4162.pdf https://www.open-std.org/jtc1/sc22/WG21/docs/papers/2014/n41...
- CyberDildonics 4y agoYou're still trying to compare one basic smart pointer implementation to garbage collection in general. You told me something was impossible to do without garbage collection and I explained three different ways that I've already done it, then you just keep trying to talk about something that was never up for discussion in the first place. You hallucinated shared_ptr into the conversation from nowhere. Without talking about smart pointers, what am I missing from the list above? Why do some lock free algorithms need garbage collection?
- pebal 4y agoI am writing about shared_ptr because C++ is one of a top language. Read about the ABA problem.
- CyberDildonics 4y agoI'm talking about C++ too, but I write lock free algorithms and data structures all the time and they have nothing to do with with smart pointers in any way. Why don't you answer my questions above? They confront the ABA problem directly since I explained three ways to keep counts paired with pointers or indices. What can't be done without a garbage collector? Why do you keep giving vague recommendations to read about general topics? Give me a specific deeply technical answer if you can.
- pebal 4y agoShow an implementation of a concurrent lock-free stack without delayed freeing.
- CyberDildonics 4y agoI think you're mixing up allocation with a data structure. There are lots of implementations of lock free lists and stacks in C++ out there. One simple implementation is an array where every index holds the next index. A current variable holds the next index to deal with and a version number. When you want to allocate an index you check the current index and version, and replace it with the index points to if the version is the same. Freeing is the reverse since you have an index to give the list. These indices are used to coordinate to a second array where you can store whatever data you want. Here are some other techniques. https://people.csail.mit.edu/shanir/publications/Lock_Free.pdf https://people.csail.mit.edu/shanir/publications/Lock_Free.p... https://www.boost.org/doc/libs/1_55_0/boost/lockfree/stack.hpp https://www.boost.org/doc/libs/1_55_0/boost/lockfree/stack.h... https://lumian2015.github.io/lockFreeProgramming/lock-free-stack.html https://lumian2015.github.io/lockFreeProgramming/lock-free-s... Still, I'm not sure what garbage collection changes about these techniques. Lock free lists have been studied for a long time, they have nothing to do with memory allocation.
- pebal 4y agoDescribed algorithms ignore the ABA problem. The boost implementation avoids the ABA problem, but does not free up memory at all and stores pointers on 48 bits which is not enough on new architectures.