From ddce1c91f8582885497b463b24bac59f6fdfdf63 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 23 Aug 2024 23:40:14 +0900 Subject: Improve handling of the global post event list in order to minimize possible crashes on exit. Key points: 1. a TQPostEventList can now have an associated mutex, which is used in case of the global post event list (GPEL) 2. the lifetime of the GPEL is no longer associated to the lifetime of the TQApplication object, but rather extended to the lifetime of the main thread. The GPEL is a static local initialized on first access and destroyed when the global static object destructor is invoked 3. access to the GPEL after the TQApplication object has been destroyed has been minimized by protecting calls in ~TQObject() and ~TQWidget(). 4. special care was taken not to affect performances or unnecessarily create tons of unused TQMutexes This replaces PR #182. Technically it is still possibly unsafe due to the order of destruction of the globat static objects not being guaranteed across multiple compilation units, but the aforementioned changes should minimize (possible to zero) the chances of a SEGV happening. Signed-off-by: Michele Calgaro --- src/kernel/tqwidget.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/kernel/tqwidget.cpp') diff --git a/src/kernel/tqwidget.cpp b/src/kernel/tqwidget.cpp index ddc34c0ec..0b27e2564 100644 --- a/src/kernel/tqwidget.cpp +++ b/src/kernel/tqwidget.cpp @@ -1003,7 +1003,10 @@ TQWidget::~TQWidget() childObjects = 0; } - TQApplication::removePostedEvents( this ); + if ( tqApp ) + { + TQApplication::removePostedEvents( this ); + } destroy(); // platform-dependent cleanup if ( extra ) -- cgit v1.2.1