It is so difficult to cancel an execution in GUI written in OCaml.
To cancel a long program run in Acumen GUI, it seems that I have the following problems:
(1) If using singe thread, a "cancel" signal will be pended until current (long) computation is completed, which makes it potentially useless.
(2) Thread is so inconvenient to use in OCaml! There are several problems:
First, if using "fork", it turns out to be that I cannot update the GUI from within my callback thread. In practice, no thread other than the main thread (aka "GUI-thread") may update any widget (that is, no call to QWidget::update(), QWidget::setFoo() etc. from another thread).
So I tried the following: In my worker thread put events into the Qt event queue and inform the GUI thread that it needs to update its GUI state according to the "model" (that is, my sound data). But things are still messed up, and eventually, "Unix.kill" or "Thread.kill" are neither implemented in OCaml!
(3) I solved the problem by a somehow nasty trick:
I break my mega computation into something that can get done in pieces and have [eval prog1] return true or false based on whether it has more work to do. Then schedule it using [Idle.add], and it'll keep running in chunks until it's done, but the GUI will still get time to process events (and allow you to kill the task by removing it from the idle loop).
Tuesday, February 26, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment