From c85f29c8d1a2c620401b9bec4c46868ecc21c1ff Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Thu, 15 Apr 2021 11:42:24 +0200 Subject: [PATCH] Converting a static variable into a shared_ptr is a bad idea, start with a shared_ptr from the start --- simgear/emesary/test_emesary.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/simgear/emesary/test_emesary.cxx b/simgear/emesary/test_emesary.cxx index 4b9e720a..0ab974aa 100644 --- a/simgear/emesary/test_emesary.cxx +++ b/simgear/emesary/test_emesary.cxx @@ -63,21 +63,21 @@ protected: //System.Threading.Interlocked.Increment(ref nthread); //var rng = new Random(); - TestThreadRecipient r; + SGSharedPtr r = new TestThreadRecipient; char temp[100]; sprintf(temp, "Notif %d", threadId); printf("starting thread %s\n", temp); TestThreadNotification tn((const char*)&r); for (int i = 0; i < MaxIterations; i++) { - simgear::Emesary::IReceiverPtr ir(&r); + simgear::Emesary::IReceiverPtr ir(r); simgear::Emesary::GlobalTransmitter::instance()->Register(ir); simgear::Emesary::GlobalTransmitter::instance()->NotifyAll(tn); simgear::Emesary::GlobalTransmitter::instance()->DeRegister(ir); //System.Threading.Thread.Sleep(rng.Next(MaxSleep)); noperations++; } - printf("%s invocations %d\n", temp, (int)r.receiveCount); + printf("%s invocations %d\n", temp, (int)r->receiveCount); printf("finish thread %s\n", temp); } }; @@ -106,9 +106,9 @@ public: void testEmesaryThreaded() { - TestThreadRecipient r; - simgear::Emesary::IReceiverPtr ir(&r); - TestThreadNotification tn((const char*)&r); + SGSharedPtr r = new TestThreadRecipient; + simgear::Emesary::IReceiverPtr ir(r); + TestThreadNotification tn((const char*)r.ptr()); simgear::Emesary::GlobalTransmitter::instance()->Register(ir); for (int i = 0; i < MaxIterations*MaxIterations; i++) {