[plt-scheme] blocking threads in mred

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Apr 9 10:49:11 EDT 2005

At Fri, 8 Apr 2005 14:46:39 -0500, Corey Sweeney wrote:
> In mred, frame%'s display and continue, whereas dialog%'s stop when
> (show #t)'d, and wait for the window to close.
> 
> When i was writing the guibuilder howto, I ran into a situation where
> i had a frame and wanted it to act like a dialog.
>
> [...]
> 
> Anyway, I have a new similar situation, but this time i was hopeing to
> not block the menus & other objects in the system, while still
> returning a value to the caller of the blocking object.  yield seems
> to block everything including the menus.

If you just run `(yield)' or `(yield (make-semaphore))' in an
eventspace's handler thread, all controls (including menus) for the
eventspace should continue to respond.

In contrast, if a handler thread is blocked with `sync' or
`thread-wait' while waiting for another thread, then GUI elements will
be blocked ---- even if the other thread runs `(yield (make-semaphore))',
because `yield' is just another name for `sync' in a non-handler
thread. I'm don't know whether that's what you're seeing, but maybe it's
something like that.

Below is an example of making a frame behave like a dialog.

Matthew

----------------------------------------

(define blocking-show-frame% 
  (class frame%
    (inherit is-shown?
	     show)

    (define s (make-semaphore))

    (define/public (blocking-show show?)
      (unless (equal? (is-shown?) (and show? #t))
	(if show?
	    (begin
	      (show #t)
	      (yield s))
	    (begin
	      (show #f)
	      (semaphore-post s)))))

    (define/augment (on-close)
      (blocking-show #f)
      (inner (void) on-close))

    (super-new)))

(define f (new blocking-show-frame%
	       [label "Test"] [width 200] [height 200]))

(define mb (new menu-bar% [parent f]))
(define m (new menu% [label "File"] [parent mb]))
(new menu-item% [label "Close"] [parent m]
     [callback (lambda (m e)
		 (send f blocking-show #f))])


(send f blocking-show #t)
(printf "All done!\n")



Posted on the users mailing list.