[
https://issues.apache.org/jira/browse/LOGCXX-532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17464869#comment-17464869
]
Dr Stephen L S Webb edited comment on LOGCXX-532 at 12/24/21, 3:07 AM:
-----------------------------------------------------------------------
Accessing repository using rep = repository.lock() in Logger::isDisabled()
causes all threads to be serialized when they test if their logger is enabled.
I suggest Hierarchy hold std::weak_ptr for the Loggers instead of
std::shared_ptr in LoggerMap.
Logger can hold a raw pointer to the LoggerRepository. The LoggerRepository
destructor should then do
{code:java}
for (auto& item : this->loggers)
{
if (auto pLogger = item.second.lock())
pLogger->resetRepository();
}{code}
Logger can then test for a NULL repositiory instead of lock() on the weak
pointer
was (Author: stephen.webb):
I suggest Hierarchy hold a weak pointers to the Loggers instead of share_ptr in
LoggerMap.
Logger can hold a raw pointer to the LoggerRepository. The LoggerRepository
destructor should then do
{code:java}
for (auto& item : this->loggers)
{
if (auto pLogger = item.second.lock())
pLogger->resetRepository();
}{code}
Logger can then test for a NULL repositiory instead of lock() on the weak
pointer
> Static objects and deleting
> ---------------------------
>
> Key: LOGCXX-532
> URL: https://issues.apache.org/jira/browse/LOGCXX-532
> Project: Log4cxx
> Issue Type: Improvement
> Reporter: Robert Middleton
> Assignee: Robert Middleton
> Priority: Minor
>
> As seen in LOGCXX-430 and LOGCXX-322, making sure that when an application
> terminates earlier than expected we don't crash is rather hard to do.
> I came across this solution when researching this problem:
> https://stackoverflow.com/a/470545/624483
> My thought is that we create something like a log4cxx::Globals class, which
> contains a smart pointer to everything that must be kept alive before the
> library can safely be unloaded. In each thread, you would do something like:
> {{GlobalsPtr globals = log4cxx::globals;}}
> thus ensuring that the destructor can't run before all of the threads are
> stopped. This would be up to the user of the library.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)