in reply to Re^2: Win32::GUI window freezing, even with threading. (Wrong solution)
in thread Win32::GUI window freezing, even with threading.

That main sub is going to thrash the life out of the CPU (100% of one core (at least; possibly more) even when nothing is happening.)

How to fix that?

Moving to Tk instead of Win32::GUI to address the OPs problem is a mistake as well.

Well, it wasn't really meant to address the OPs problem, I just don't Win32::GUI much

The mistake the OP is making is to try handing the responsibility of adding the data to the GUI list back to the event-loop thread.

Which translates into what linechanges in OPs code?

:)

  • Comment on Re^3: Win32::GUI window freezing, even with threading. (Wrong solution)

Replies are listed 'Best First'.
Re^4: Win32::GUI window freezing, even with threading. (Wrong solution)
by BrowserUk (Patriarch) on May 28, 2013 at 09:07 UTC
    How to fix that?

    Don't use yield:

    threads->yield();

    That effectively equates to sleep( 0 ), which whilst it ensures that other threads get a timeslice, equates to:

    saveThreadContext; restoreThreadContext;

    when there are no other threads available to run; which is a cpu costly way to implement a delay.

    Replace it with Win32::Sleep( 33 ) will ensure that the gui remains responsive at speed faster than the eye can detect, but will drop the cpu usage of that thread to near 0.

    Which translates into what linechanges in OPs code?

    Should be as simple as:

    #######my $DataQueue = Thread::Queue->new(); ... #wait for data, print data to GUI textbox #######while(Win32::GUI::DoEvents() != -1) { ####### my $tmptxt = $DataQueue->dequeue(); ####### $main_text_window->Append($tmptxt); #######} Win32::GUI::Dialog(); sub mainloop { while (1) { #lots of page getting and number crunching goes here ########## $DataQueue->enqueue("some data"); $main_text_window->Append($tmptxt); } }

    Though that is untested.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.