[plt-scheme] Idiom for suspending the top level thread

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jun 13 07:08:31 EDT 2006

At Tue, 13 Jun 2006 03:54:04 -0700 (PDT), Noel Welsh wrote:
> What is the preferred idiom for suspending the top level
> thread to stop a program exiting? 

My favorite is
 (sync (make-semaphore))
or, in MrEd,
 (yield (make-semaphore))

>  (let loop () (loop))  ;; busy wait

Definitely not.  :)

>  (thread-suspend (current-thread))

This is probably not a good idea, since suspending the main thread
prevents handling break signals. If the other threads finish without
resuming the main thread, MzScheme will complain with "unbreakable
deadlock" and immediately exit.

>  (thread-wait (current-thread))

This one is fine.


Posted on the users mailing list.