Unsolved Infinite lock wait issue when emitting signal and datatype is not registered.
-
Hi and welcome to devnet,
How is your logger implemented ?
-
The actual file logging happens in a separate thread which catches a signal called logEvent. The logEvent signal is emitted by a util class , called Logger, that anyone can call.
When we detect a qWarning we call a function on the logger. This is implemented with the qInstallMessageHandler API.
So something like this:void qMessageAsLogHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) { Q_UNUSED(context); switch (type) { case QtDebugMsg: case QtInfoMsg: case QtWarningMsg: Logger::log(LogWarning, msg); break; .... } } void Logger::log(type, msg) { emit logEvent(type, msg); } void Logger::installQtMsgHandler() { qInstallMessageHandler(qMessageAsLogHandler); }
-
I wouldn't call a signal directly from the message handler. I would queue it.
-
What do you mean by that, that the connect to the signals from the message handler should be queued connections? But this problem is independent of that, as the lock from the message handler 's activate call happens before it checks if there are any queued connections.
-
You don't get the lock if you don't emit that signal correct ?
-
Yes. No lock if no signal is emitted. The lock happens inside the 'emit signal' call.
-
Hence my suggestion of queuing that signal emit.
-
But doesn't the queuing happens inside the 'emit signal' code, based on whether the receiver's connection is 'QueuedConnection' or if the receiver's thread is different than the emitting thread.
Is there another way of 'queuing the signal'. -
Update to 5.9.8 at least.[Edit: no good]
From what I saw in the current source (dev) the lock's been moved down and the actual type checks are made lockless through atomics.Well, 5.13.x locks the same mutex at the same place, in dev it's been switched to atomics. So @SGaist's advice applies - use a workaround - queue the signal of your intercepting handler instead of emitting it directly.
@arunr said in Infinite lock wait issue when emitting signal and datatype is not registered.:
Is there another way of 'queuing the signal'.
QMetaObject::invokeMethod with
Qt::QueuedConnection
. -
OK. Thanks. Will do.