Skip to content

Commit 7ffc743

Browse files
committed
Ensure the dispatch thread has terminated before destroying the std::thread
1 parent ecc8011 commit 7ffc743

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/main/cpp/asyncappender.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,21 @@ typedef std::map<LogString, DiscardSummary> DiscardMap;
115115

116116
struct AsyncAppender::AsyncAppenderPriv : public AppenderSkeleton::AppenderSkeletonPrivate
117117
{
118-
AsyncAppenderPriv() :
119-
AppenderSkeletonPrivate(),
120-
buffer(DEFAULT_BUFFER_SIZE),
121-
bufferSize(DEFAULT_BUFFER_SIZE),
122-
dispatcher(),
123-
locationInfo(false),
124-
blocking(true)
125-
#if LOG4CXX_EVENTS_AT_EXIT
126-
, atExitRegistryRaii([this]{stopDispatcher();})
127-
#endif
118+
AsyncAppenderPriv()
119+
: AppenderSkeletonPrivate()
120+
, buffer(DEFAULT_BUFFER_SIZE)
121+
, bufferSize(DEFAULT_BUFFER_SIZE)
122+
, dispatcher()
123+
, locationInfo(false)
124+
, blocking(true)
128125
, eventCount(0)
129126
, dispatchedCount(0)
130127
, commitCount(0)
128+
{ }
129+
130+
~AsyncAppenderPriv()
131131
{
132+
stopDispatcher();
132133
}
133134

134135
/**
@@ -191,10 +192,6 @@ struct AsyncAppender::AsyncAppenderPriv : public AppenderSkeleton::AppenderSkele
191192
*/
192193
bool blocking;
193194

194-
#if LOG4CXX_EVENTS_AT_EXIT
195-
helpers::AtExitRegistry::Raii atExitRegistryRaii;
196-
#endif
197-
198195
/**
199196
* Used to calculate the buffer position at which to store the next event.
200197
*/

src/test/cpp/asyncappendertestcase.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ class AsyncAppenderTestCase : public AppenderSkeletonTestCase
310310
LOG4CXX_INFO(root, "Message");
311311
auto& v = vectorAppender->getVector();
312312
LOGUNIT_ASSERT(0 < v.size());
313-
asyncAppender->close(); // Wait for dispatch thread to complete
314313
}
315314

316315
/**

0 commit comments

Comments
 (0)