[racket] Threads, Windows, and World

From: Drew Hess (drew.hess at gmail.com)
Date: Thu Mar 3 12:52:54 EST 2011

On Thu, Mar 3, 2011 at 9:26 AM, Drew Hess <drew.hess at gmail.com> wrote:

> Add a couple of WAV file names to the song-list variable in
> drew-game.ss, make sure they're in the same directory as drew-game.ss,
> and run the program on Mac OS X. Observe that songs play back fine
> while the game is running (except that, as I mentioned above,
> they keep playing when the game window is closed; I would love to
> know how to hook a window-closed event so that I can kill the thread
> when this happens).

Oh! I forgot to mention, and this is very important: if you test this
on Mac OS X, on Racket 5.1, you must first invert the play-sound
async flag in the thread's loop! i.e., change the loop to read:

(letrec ((loop-songs
  (lambda ()
    (begin
      (map
        (lambda (filename) (play-sound filename #t)) ; very important,
make sure this is #t !
         song-list)
      (loop-songs)))))
 (loop-songs))

Otherwise, due to the bug in play-sound on Mac OS X that inverts
the meaning of the async flag, this loop will turn into a
play-sound bomb: it won't wait for the previous play-sound
call to finish before starting the next song, ad infinitum!

(That was *not* a fun one to debug, trying to kill DrRacket
while it ate up all the available memory on my Mac and played
a sound that sounded like the universe was collapsing.)

d


Posted on the users mailing list.