swebb2066 commented on PR #586:
URL: https://github.com/apache/logging-log4cxx/pull/586#issuecomment-3838698463
> but this fixes the immediate segfault
I still observe a crash when running the new test repeatedly. I believe this
is because the dispatch thread is not quiescent when the test calls
setBufferSize(newSize).
I suggest the following simpler change to asyncappender.cpp. It does not
require the dispatch thread is quiescent before setBufferSize() is called. The
new test does not crash when run repeatedly.
```
diff --git a/src/main/cpp/asyncappender.cpp b/src/main/cpp/asyncappender.cpp
index 8443d46f..faa86fb2 100644
--- a/src/main/cpp/asyncappender.cpp
+++ b/src/main/cpp/asyncappender.cpp
@@ -250,6 +250,11 @@ struct AsyncAppender::AsyncAppenderPriv : public
AppenderSkeleton::AppenderSkele
* Used to ensure the dispatch thread does not wait when a logging
thread is waiting.
*/
alignas(hardware_constructive_interference_size) int blockedCount{0};
+
+ /**
+ * Used to suspend use of the ring buffer.
+ */
+ alignas(hardware_constructive_interference_size) bool
resizing{false};
};
@@ -304,7 +309,7 @@ void AsyncAppender::doAppend(const spi::LoggingEventPtr&
event, Pool& pool1)
void AsyncAppender::append(const spi::LoggingEventPtr& event, Pool& p)
{
- if (priv->bufferSize <= 0)
+ if (priv->bufferSize <= 0 || priv->resizing)
{
priv->appenders.appendLoopOnAppenders(event, p);
return;
@@ -472,9 +477,16 @@ void AsyncAppender::setBufferSize(int size)
throw IllegalArgumentException(LOG4CXX_STR("size argument
must be non-negative"));
}
+ priv->resizing = true;
+ while (priv->commitCount != priv->dispatchedCount)
+ {
+ priv->bufferNotEmpty.notify_all();
+ std::this_thread::yield(); // Wait a bit
+ }
std::lock_guard<std::mutex> lock(priv->bufferMutex);
priv->bufferSize = (size < 1) ? 1 : size;
priv->buffer.resize(priv->bufferSize);
+ priv->resizing = false;
priv->bufferNotFull.notify_all();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]