[racket] CPU-heavy operations and GUI responsiveness

From: Michael W (mwilber at uccs.edu)
Date: Fri Apr 13 09:38:45 EDT 2012

Hey, Racketeers!

So I have a program that does a bunch of expensive image
processing, but I want it to interactively draw its results to a
canvas% as it runs.

Only problem is events: I also want it to, say, stop right when I
close the window or furiously mash Esc, for example.

I've found that the built-in GUI handler thread never gets around
to processing the events while the scientific part of the program
is running unless I do something like (sleep 0.1) every so often,
which, if done too often, slows the program down of course. Even
calling (yield) in my CPU-intensive routines doesn't seem to
drain the GUI event queue (it seems to only be effective within
event callbacks? is my understanding right?)

The only way I've found of making it responsive is to organize
the work into tiny bunches scheduled with (queue-callback ...
#f). Is there a better way of doing this? Are there hidden
consequences that I should be aware of?

It would be awesome (or horrifying?) to somehow get at the
low-level thread scheduling machinery and give the built-in GUI
handler thread "scheduling priority" over the image processing
thread. Unless it doesn't work that way or my understanding is

Have a pizza,

Posted on the users mailing list.