[plt-scheme] current-directory and eventspaces

From: Robert Bruce Findler (robby at cs.uchicago.edu)
Date: Mon Dec 16 18:31:25 EST 2002

The current-directory is thread-specific. When you create an
eventspace, you create a new thread. With the commented line
uncommented, you are setting the current directory in one thread (the
original thread -- the main thread of the original eventspace) and then
looking it up in a different thread (the callbacks are handled on the
main thread of the eventspace that the frame is registered with).
Probably what you want is to move the frame creation over to the other
thread, like this:

  (current-eventspace (make-eventspace))
  (queue-callback
    (lambda ()
      (instantiate dir-tester% ()
        (label "Dir Tester 1")
        (dir "/tmp")))))

Robby

At Mon, 16 Dec 2002 17:13:17 -0600, Jefferson Provost wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> I'm having some trouble understanding how changing the current directory 
> interacts with different eventspaces.
> 
> The example below creates a specialized frame which changes the current 
> directory upon instantiation.  If the new frame is created in a new 
> eventspace, the current directory change doesn't seem to "take". 
> However, if the object changes the current directory again, after 
> instantiation, then it works.
> 
> Without the new eventspace, everything seems to work normally.  I don't 
> get it...
> 
> J.
> 
> ;;;;;
> 
> 
> 
> (define dir-tester%
>    (class frame%
> 
>      ; internal directory field
>      (init-field dir)
> 
>      (super-instantiate ())
> 
>      (instantiate button% ()
>        (parent this)
>        (label "Print dir")
>        (callback
>         (lambda (b e)
>           (printf "dir = ~S~% (current-directory) = ~S~%"
>                   dir (current-directory)))))
> 
> 
>      (instantiate button% ()
>        (parent this)
>        (label "Select dir")
>        (callback
>         (lambda (b e)
>           (set! dir (get-directory))
>           ; set the current directory here after selection
>           (current-directory dir))))
> 
>      ; set the current directory here on initialization
>      (printf "Supposedly setting current-directory to ~S~%" dir)
>      (current-directory dir)
>      (printf "current-directory is supposedly now ~S~%"
>              (current-directory))
>      ))
> 
> 
> ;
> ; Comment out next line to see correct behavior
> (current-eventspace (make-eventspace))
> 
> (define tester1
>    (instantiate dir-tester% ()
>      (label "Dir Tester 1")
>      (dir "/tmp")))
> 
> (send tester1 show #t)



Posted on the users mailing list.