2 hours ago, DerTroll said:
I guess writing your own implementation shouldn't be too hard and its the best way to get exactly what you need.
That's effectively not hard once you know what reference-counting smart pointers are. But why ? This will definitely be incompatible with standard smart pointers. Also, the OP has issues only with multithreading. And there exists ways to use std smart pointers well in multithreaded environments (fortunately). Also, making everything thread-safe is certainly not the best choice. And smart pointers are already slower than raw pointers. So why making them even more slow ?
2 hours ago, DerTroll said:
You can also just copy the code of the boost or STL shared pointer and adjust it to your needs.
Depending on what the clauses of the licenses would allow.
2 hours ago, DerTroll said:
Personally, I also don't like shared pointers. They seem always like an easy solution to many problems, but most of the times they just make your code way more complicated since object lifetime gets much harder to predict. In the worst case, you create a circular dependency which results in a really mean kind of memory leak. However, there are situations where they are really a good choice. It's like always: Select the correct tool for your problem.
Unfortunately SP are well sit on the road nowadays. The fact that we like them or not might not suffice depending on which projects we are working with. I personally try to avoid them too since they have a performance consideration, did not prove to get rid of memory leaks, neither to ease the memory use, and they can easily get very hard to use once you want to use them well (ie in multithreading, or with using other smart pointers as unique_ptr or so, or to cast them, or in hybrid environments...). At the end, you get them everywhere, in different forms (ie having both typenames for unique an shared ptr in any classes, casts everywhere, copies everywhere, nullptr tests everywhere...).
I am not the one who down-voted (I dislike this since it is mainly too easily used and mostly cowardly used), but the answer of Gnollrunner was out-of-topic since OP clearly stated that:
9 hours ago, svetpet said:
I am multithreading large piece of code
So this is not suitable to ask the OP to simply remove his smart pointer uses neither to tell we dislike them.
Finally using well smart pointers is not an easy piece. There are good books treating about this. And this involves to use more broadly the standard library.