Re: FXMessageChannel::message() sometimes hangs on main thread
[email protected] Wed, 11 Dec 2024 09:29:31 -0600
| Newsgroups | gmane.comp.lib.fox-toolkit.user |
|---|---|
| Message-ID | <[email protected]> |
On 2024-12-11 08:53, Roland Plüss via Foxgui-users wrote:
> I try to use FXMessageChannel to receive logs. The call to
> FXMessageChannel::message() can though happen from a worker thread or
> the main thread. Debugging a hang of the application it seems the hang
> happens inside FXMessageChannel::message() while called from the main
> thread. Is there a way to detect if I'm in the main (UI thread) using
> FOX means or not?
Main GUI thread should *not* use FXMessageChannel to talk to itself.
FXMessageChannel uses a pipe. The idea is to wake the consumer when
there's activity on the pipe, i.e. there's data ready to read.
The GUI (main) thread watches this pipe in its event loop, i.e. when
it returns to the event loop, in addition to mouse, keyboard [etc]
messages, it also checks for pipes and sockets.
When the main thread is doing stuff, it is usually in response to some
event. Normally, the main thread sits in the select() [on Windows,
MsgWaitForMultipleObjects()] system call, until one of the sources
or a timeout wakes it up.
Thus, its able to process messages posted by worker threads via
FXMessageChannel, which can then be abled in the context of the
main thread.
If it starts using FXMessageChannel to "talk to itself" then messages
can pile up as they won't get handled until returning to the event loop.
A problem exists if the pipe data buffer is full. In that case, the
write system call blocks until the buffer gets emptied by the consumer.
As you will no doubt realize by now, it is its own consumer and thus
no one will drain the pipe buffer while its blocked in the write.
Result is we'll hang indefinitely.
Of course, if the main thread wants to execute a message in its own
context, there's really no need to use FXMessageBuffer at all; one
could simply just call the handler directly...
Hope this explains what you're seeing...
-- JVZ
_______________________________________________
Foxgui-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/foxgui-users