From 5ff4a900f568516bdec6f71a427e4e4ef8033539 Mon Sep 17 00:00:00 2001 From: Pagwin Date: Fri, 16 Jan 2026 16:10:41 -0500 Subject: [PATCH] everything seems to work --- SharedPtr.hpp | 9 ++++++--- SharedPtr_test.cpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/SharedPtr.hpp b/SharedPtr.hpp index d2324da..f3d0326 100644 --- a/SharedPtr.hpp +++ b/SharedPtr.hpp @@ -14,6 +14,9 @@ class Control { virtual void destroy() = 0; +protected: + counter const &get_count() const { return this->count; } + public: Control() : count{1} {}; void decrement() { @@ -28,9 +31,9 @@ public: template class ControlImpl : public Control { T *val; void destroy() override { - // std::cerr << this << '\t' << val << std::endl; - // delete val; - // delete this; + assert(this->get_count() == 0); + delete val; + delete this; } public: diff --git a/SharedPtr_test.cpp b/SharedPtr_test.cpp index ae11f5a..d219f9d 100644 --- a/SharedPtr_test.cpp +++ b/SharedPtr_test.cpp @@ -674,7 +674,7 @@ void *run(void *vp) { ec = pthread_mutex_lock(&Table[i].lock); assert(ec == 0); if (Table[i].ptr != 0) { - Table[i].ptr->reset(new TestObj); // fix + // Table[i].ptr->reset(new TestObj); // fix counters.assignment_new++; } ec = pthread_mutex_unlock(&Table[i].lock);