[ 
https://issues.apache.org/jira/browse/AMQCPP-564?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17401844#comment-17401844
 ] 

Rick Guzman commented on AMQCPP-564:
------------------------------------

I think there is still problems with this.  I am running version 3.9.3, and see 
the newly added function releaseCurrentThreadHandle(), but no one is calling 
that function.  When using valgrind to analyze memory, I'm seeing consistent 
memory growth showing the following stack

decaf::internal::util::concurrent::Threading::attachToCurrentTHread() 
(Threading.cpp:958)
decaf::internal::util::concurrent::Threading::getCurrentThreadHandle() 
(Threading.cpp:1332)
decaf::internal::util::concurrent::Threading::enterMonitor(decaf::internal::util::concurrent::MonitorHandle*)
 (Threading.cpp:1533)
decaf::util::concurrent::Mutex::lock() (Mutex.cpp:129)
decaf::util::concurrent::Lock::lock() (Lock.cpp:54)
decaf::util::concurrent::Mutex::Lock::Lock(decaf::util::concurrent::Synchronizable*,
 bool) (Lock.cpp:32)
activemq::util::LongSequenceGenerator::getNextSequenceId() 
(LongSequenceGenerator.cpp:36)
activemq::core::ActiveMQConnection::getNextSessionId() 
(ActiveMQConnection.cpp:578)
activemq::core::ActiveMQConnection::createSession(cms::Session::AcknowledgeMode)
 (ActiveMQConnection.cpp:562)
activemq::core::ActiveMQConnection::createSession() (ActiveMQConnection.cpp:545)

 

It seems like Threading::exitMonitor() or Threading::doMonitorExit() needs to 
call the new function, releaseCurrentThreadHandle().

 

 

> OS thread handles are kept forever
> ----------------------------------
>
>                 Key: AMQCPP-564
>                 URL: https://issues.apache.org/jira/browse/AMQCPP-564
>             Project: ActiveMQ C++ Client
>          Issue Type: Improvement
>          Components: Decaf
>    Affects Versions: 3.8.3
>         Environment: All
>            Reporter: Dusan Kutnik
>            Assignee: Timothy A. Bish
>            Priority: Major
>             Fix For: 3.9.0
>
>         Attachments: Threading.cpp.diff, Threading.h.diff
>
>
> The method 
> decaf::internal::util::concurrent::Threading::attachToCurrentThread() creates 
> a proxy thread object for a new OS thread and keeps it in a vector:
> ////////////////////////////////////////////////////////////////////////////////
> ThreadHandle* Threading::attachToCurrentThread() {
>     Pointer<ThreadHandle> thread(initThreadHandle(new ThreadHandle()));
>     thread->handle = PlatformThread::getCurrentThread();
>     thread->state = Thread::RUNNABLE;
>     thread->stackSize = PlatformThread::getStackSize(thread->handle);
>     thread->name = ::strdup(
>         std::string(std::string("OS-Thread") + 
> Integer::toString(library->osThreadId.getAndIncrement())).c_str());
>     thread->threadId = PlatformThread::getCurrentThreadId();
>     // An OS Thread doesn't have a running thread, this is only a proxy to 
> only one ref.
>     thread->references = 1;
>     // Now create a Decaf Thread as a proxy to the OS thread.
>     Pointer<Thread> osThread(new Thread(thread.get()));
>     thread->parent = osThread.get();
>     thread->osThread = true;
>     PlatformThread::setTlsValue(library->threadKey, osThread.get());
>     PlatformThread::setTlsValue(library->selfKey, thread.get());
>     // Store the Thread that wraps this OS thread for later deletion since
>     // no other owners exist.
>     PlatformThread::lockMutex(library->globalLock);
>     library->osThreads.push_back(osThread.release());
>     PlatformThread::unlockMutex(library->globalLock);
>     return thread.release();
> }
> This method is part of the mutex machinery in the AMQ CPP. The only way how 
> to free this memory is to invoke the method 
> decaf::internal::util::concurrent::Threading::shutdown(). In our scenario we 
> create continuously new worker threads that communicate with ActiveMQ broker. 
> This leads to the situation that new OS thread handles are still being 
> created and never freed. The consumed RAM is rapidly growing since the size 
> of the thread object is on our platform (Win 64bit) 1632 Bytes. We would need 
> to have possibility to explicitly free this OS thread object before it 
> terminates, for instance something like:
> void decaf::internal::util::concurrent::Threading::detachFromCurrentThread()
> Is there a reasonable workaround or another way how to free this OS thread?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to