wxGTK: Not getting any idle messages under heavy CPU load

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

wxGTK: Not getting any idle messages under heavy CPU load

Andreas Falkenhahn
I do some important stuff in a handler for wxEVT_IDLE. Sometimes I have
a worker thread which does some stuff that is heavy on the CPU. Still,
I'd need the main thread to run the handler for wxEVT_IDLE every now and
then. That's why my worker thread calls wxWakeUpIdle() in regular
intervals.

However, the idle handler is never called when there's heavy load on
the CPU by my worker thread. Even clicking a button in my window
doesn't trigger the idle handler although I was of the impression that
standard UI events should trigger idle events in any case. So is this
really supposed to behave like that? If it is, what should I do to force
the idle handler to be run? Post a wxEVT_IDLE event myself?

The backend is wxGTK on an older PowerPC Linux running on a single
core CPU.

--
Best regards,
 Andreas Falkenhahn                          mailto:[hidden email]

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: wxGTK: Not getting any idle messages under heavy CPU load

Kenneth Porter
On 2/21/2017 10:28 AM, Andreas Falkenhahn wrote:
> I do some important stuff in a handler for wxEVT_IDLE. Sometimes I have
> a worker thread which does some stuff that is heavy on the CPU. Still,
> I'd need the main thread to run the handler for wxEVT_IDLE every now and
> then. That's why my worker thread calls wxWakeUpIdle() in regular
> intervals.
Why is it in the GUI thread?  Is it display-related?

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: wxGTK: Not getting any idle messages under heavy CPU load

Andreas Falkenhahn
On 21.02.2017 at 19:58 Kenneth Porter wrote:

> On 2/21/2017 10:28 AM, Andreas Falkenhahn wrote:
>> I do some important stuff in a handler for wxEVT_IDLE. Sometimes I have
>> a worker thread which does some stuff that is heavy on the CPU. Still,
>> I'd need the main thread to run the handler for wxEVT_IDLE every now and
>> then. That's why my worker thread calls wxWakeUpIdle() in regular
>> intervals.
> Why is it in the GUI thread?  Is it display-related?

Yes.

--
Best regards,
 Andreas Falkenhahn                            mailto:[hidden email]

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re:Re: wxGTK: Not getting any idle messages under heavy CPU load

krishnaLee
If let me handle the question,I will use custom_GUI_event inherit wxCommandEvent ,and write a eventHandler for the custom event.then call ProcessWindowEvent(customEvent) in the work thread for process the custom_GUI_event.<br/>(the custom_GUI_event  will processed in main thread,for GUI_event or not,all should work well.)
At 2017-02-22 03:17:51, "Andreas Falkenhahn" <[hidden email]> wrote:

>On 21.02.2017 at 19:58 Kenneth Porter wrote:
>
>> On 2/21/2017 10:28 AM, Andreas Falkenhahn wrote:
>>> I do some important stuff in a handler for wxEVT_IDLE. Sometimes I have
>>> a worker thread which does some stuff that is heavy on the CPU. Still,
>>> I'd need the main thread to run the handler for wxEVT_IDLE every now and
>>> then. That's why my worker thread calls wxWakeUpIdle() in regular
>>> intervals.
>> Why is it in the GUI thread?  Is it display-related?
>
>Yes.
>
>--
>Best regards,
> Andreas Falkenhahn                            mailto:[hidden email]
>
>--
>Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
>
>To unsubscribe, send email to [hidden email]
>or visit http://groups.google.com/group/wx-users

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: wxGTK: Not getting any idle messages under heavy CPU load

Andreas Falkenhahn
Thinking about it further, I think it is a bug in wxGTK. The documentation
of wxIdleEvent says this:

"Note that, unless you do something specifically, the idle events are not sent
if the system remains idle once it has become it, e.g. only a single idle event
will be generated until something else resulting in more normal events happens
and only then is the next idle event sent again."

To me this sounds like as if there has to be another idle event after the
user has pressed a button. But in the case of heavy CPU load this isn't
the case! The wxCommandEvent for pressing the button is triggered all right,
but it is never followed by a wxIdleEvent in case of heavy CPU load! Dispatching
of wxIdleEvent seems to stop completely under heavy CPU load.

Is this a bug or did I misunderstand something here?

--
Best regards,
 Andreas Falkenhahn                            mailto:[hidden email]

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: wxGTK: Not getting any idle messages under heavy CPU load

Fabian Cenedese
At 16:16 22.02.2017, Andreas Falkenhahn wrote:

>Thinking about it further, I think it is a bug in wxGTK. The documentation
>of wxIdleEvent says this:
>
>"Note that, unless you do something specifically, the idle events are not sent
>if the system remains idle once it has become it, e.g. only a single idle event
>will be generated until something else resulting in more normal events happens
>and only then is the next idle event sent again."
>
>To me this sounds like as if there has to be another idle event after the
>user has pressed a button. But in the case of heavy CPU load this isn't
>the case! The wxCommandEvent for pressing the button is triggered all right,
>but it is never followed by a wxIdleEvent in case of heavy CPU load! Dispatching
>of wxIdleEvent seems to stop completely under heavy CPU load.

Is this your application producing the CPU load? Idle seems
contradictory to heavy CPU load. Why would you expect an
idle event if the CPU is everything else but idle? Sounds to me
like you rather need a timer that periodically generates an event
for your application where you can do something or just skip it.

bye  Fabi

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: wxGTK: Not getting any idle messages under heavy CPU load

Andreas Falkenhahn
On 22.02.2017 at 16:33 Fabian Cenedese wrote:

> At 16:16 22.02.2017, Andreas Falkenhahn wrote:

>>Thinking about it further, I think it is a bug in wxGTK. The documentation
>>of wxIdleEvent says this:

>>"Note that, unless you do something specifically, the idle events are not sent
>>if the system remains idle once it has become it, e.g. only a single idle event
>>will be generated until something else resulting in more normal events happens
>>and only then is the next idle event sent again."

>>To me this sounds like as if there has to be another idle event after the
>>user has pressed a button. But in the case of heavy CPU load this isn't
>>the case! The wxCommandEvent for pressing the button is triggered all right,
>>but it is never followed by a wxIdleEvent in case of heavy CPU load! Dispatching
>>of wxIdleEvent seems to stop completely under heavy CPU load.

> Is this your application producing the CPU load?

Yes.

> Idle seems contradictory to heavy CPU load. Why would you expect an
> idle event if the CPU is everything else but idle?

Because to me it sounds like wxWidgets promises to send an idle event
after a "more normal event" has happened (see documentation of wxIdleEvent
which I quoted above), i.e. in my case I'd expect wxWidgets to trigger an
idle event after I have pressed a button, no matter how busy the CPU currently
is. But in case of heavy CPU load, there is no ensuing idle event after the
user has pressed a button.

I also think that we should distinguish between the two threads:

1) The worker thread is really busy and heavy on the CPU.

2) The main thread, however, doesn't have anything to do, so it actually
*is* idle. If I understand idle events correctly, then they should be sent if
there are no other events in the queue, regardless of how busy the CPU currently
is. And that is clearly the case in my project: The main thread doesn't have
anything to do, it *is* idle (even though the worker thread is really heavy on
the CPU, but that is completely unrelated to the main thread).

In other words: From my point of view it is no contradiction that the CPU
is at 100% and the main thread is idle. Only the worker thread is really busy,
the main thread is idle and thus also should receive idle events.

--
Best regards,
 Andreas Falkenhahn                            mailto:[hidden email]

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: wxGTK: Not getting any idle messages under heavy CPU load

Eric Jensen-10
In reply to this post by Andreas Falkenhahn
Hello Andreas,

Wednesday, February 22, 2017, 4:16:45 PM, you wrote:

AF> Thinking about it further, I think it is a bug in wxGTK. The documentation
AF> of wxIdleEvent says this:

AF> "Note that, unless you do something specifically, the idle events are not sent
AF> if the system remains idle once it has become it, e.g. only a single idle event
AF> will be generated until something else resulting in more normal events happens
AF> and only then is the next idle event sent again."

AF> To me this sounds like as if there has to be another idle event after the
AF> user has pressed a button. But in the case of heavy CPU load this isn't
AF> the case! The wxCommandEvent for pressing the button is triggered all right,
AF> but it is never followed by a wxIdleEvent in case of heavy CPU load! Dispatching
AF> of wxIdleEvent seems to stop completely under heavy CPU load.

AF> Is this a bug or did I misunderstand something here?

Inside an Idle event handler you can call wxIdleEvent::RequestMore to
request more idle events. However, this will create idle events at the
maximum rate the system can handle, so it's probably not what you
want.

For GUI updates i'd recommend a timer event at 5-20 fps depending on
the application.

If your code is running on a multicore CPU, a secondary thread should
never be able to prevent events from gettings processed. *If* you are
running on a single-core machine, you must make sure that there is
enough time to process the events, otherwise the event queue will get
saturated.

Hth,
Eric

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: wxGTK: Not getting any idle messages under heavy CPU load

Andreas Falkenhahn
On 22.02.2017 at 18:13 Eric Jensen wrote:

> Hello Andreas,

> Wednesday, February 22, 2017, 4:16:45 PM, you wrote:

AF>> Thinking about it further, I think it is a bug in wxGTK. The documentation
AF>> of wxIdleEvent says this:

AF>> "Note that, unless you do something specifically, the idle events are not sent
AF>> if the system remains idle once it has become it, e.g. only a single idle event
AF>> will be generated until something else resulting in more normal events happens
AF>> and only then is the next idle event sent again."

AF>> To me this sounds like as if there has to be another idle event after the
AF>> user has pressed a button. But in the case of heavy CPU load this isn't
AF>> the case! The wxCommandEvent for pressing the button is triggered all right,
AF>> but it is never followed by a wxIdleEvent in case of heavy CPU load! Dispatching
AF>> of wxIdleEvent seems to stop completely under heavy CPU load.

AF>> Is this a bug or did I misunderstand something here?

> Inside an Idle event handler you can call wxIdleEvent::RequestMore to
> request more idle events. However, this will create idle events at the
> maximum rate the system can handle, so it's probably not what you
> want.

> For GUI updates i'd recommend a timer event at 5-20 fps depending on
> the application.

Thanks, but of course I know many alternatives to my design as well. I'd
just like to know whether the behaviour I'm seeing here is a bug or not.

> If your code is running on a multicore CPU, a secondary thread should
> never be able to prevent events from gettings processed. *If* you are
> running on a single-core machine, you must make sure that there is
> enough time to process the events, otherwise the event queue will get
> saturated.

I'm on a single-core machine but as I said, button click events
(wxCommandEvent) *are* processed even when the system is very busy, but
wxIdleEvent doesn't come in any more even though the main thread clearly
doesn't have anything to do and should receive idle events!

--
Best regards,
 Andreas Falkenhahn                            mailto:[hidden email]

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re[2]: wxGTK: Not getting any idle messages under heavy CPU load

Vadim Zeitlin-4
On Wed, 22 Feb 2017 18:18:56 +0100 Andreas Falkenhahn wrote:

AF> I'm on a single-core machine but as I said, button click events
AF> (wxCommandEvent) are processed even when the system is very busy, but
AF> wxIdleEvent doesn't come in any more even though the main thread clearly
AF> doesn't have anything to do and should receive idle events!

 Are you sure about this? The main thread might not have enough CPU time
for repainting or maybe processing timer events. Even if this is not the
case in your program (but I'd really like to have a small patch to the
minimal sample showing this then), it's definitely quite easy to imagine
that your wxEVT_IDLE handler will be never, or very rarely, called, if the
system is never actually idle. You should definitely use a background
thread as the OS provides much better fairness guarantees than the simple
idle event generation algorithm in wxWidgets does.

 Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/

attachment0 (203 bytes) Download Attachment