[plt-scheme] Mred, exiting, and deamond threads

From: Robby Findler (robby at cs.uchicago.edu)
Date: Thu Jan 29 21:03:41 EST 2004

Defaultly, code that runs in mred is running on the eventspace's event 
handler thread (not on a thread that was started with `thread'). So, 
the code you run (say the body of those modules below) is treated as a 
callback in the initial eventspace. MrEd exits when there are no more 
callbacks to run in the initial eventspace. That is, when there are no 
more frames and no running event% objects (and there isnt' a callback 
running at the moment).

This is the eventspace handler thread's equivalent of "completion" and 
this test isn't really used anywhere else in the system.

Suspending the eventspace's thread means that you've suspended that one 
callback, so that callback hasn't finished (so mred doesn't exit). Gui 
widgets "break" because you've frozen the handler thread (so it's not 
so much the widget that broke as it was the callback you wrote that was 
broken :).

Robby

On Jan 29, 2004, at 6:44 PM, Guillaume Marceau wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
> What is the rule that gouvern when mred exits, with respect to threads?
>
> This program exits:
>
>   (module test mzscheme
>     (thread (lambda () (let loop () (display "hello\n") (sleep 1) 
> (loop)))))
>
>
> But this one doesn't:
>
>   (module test mzscheme
>     (thread (lambda () (let loop () (display "grettings\n") (sleep 1) 
> (loop))))
>     (thread-suspend (current-thread)))
>
>
> Neither does this one:
>
>   (module test mzscheme
>     (require (lib "class.ss")
>              (lib "mred.ss" "mred"))
>
>     (define frame (instantiate frame% () (label "GUI") (height 150) 
> (width 200)))
>     (send frame show #t)
>
>     (instantiate message% () (label "g'evening" frame))
>
>     (thread (lambda () (let loop () (display "g'evening\n") (sleep 1) 
> (loop)))))
>
>
> Also, if I combine the two, gui widjets break:
>
>   (module test mzscheme
>     (require (lib "class.ss")
>              (lib "mred.ss" "mred"))
>
>     (define frame (instantiate frame% () (label "GUI") (height 150) 
> (width 200)))
>     (send frame show #t)
>
>     (instantiate message% () (label "welcome" frame))
>
>     (thread (lambda () (let loop () (display "welcome\n") (sleep 1) 
> (loop))))
>     (thread-suspend (current-thread)))
>
> After the call to thread-suspend, the gui no longer refreshes.
>
>
>
>
> -- 
> "The thing I remember most about America is that it's silly.
>  That can be quite a relief at times."  -- Thom Yorke, Radiohead
>
> - Guillaume



Posted on the users mailing list.