Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: Win32::GUI window freezing, even with threading. (Wrong solution)

by BrowserUk (Patriarch)
on May 28, 2013 at 09:07 UTC ( [id://1035552]=note: print w/replies, xml ) Need Help??


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

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1035552]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-20 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found