next up previous contents index
Next: make-thread thunk procedure Up: Multithreading Previous: parallel form form ...

select (event form ...) ... syntax

 

The select form allows a nondeterministic  choice between several events. The syntax is modelled after cond.

tabular281

A guard is an expression that evaluates to an event object, a thread, or #F. All of the guard expressions are evaluated. Clauses with guard expressions evaluating to #F are eliminated from the choice. One of the remaining clauses is chosen when its event (or thread termination event) is signalled. If some clause has an event that is already in the signalled state, that clause may be chosen immediately. In the => form, procedure is called with the value associated with the event.

If all guard expressions evaluate to #F then there is no event to wait for, so execution must proceed. If there is an else-clause then the else-clause forms are executed, otherwise the whole select-from finishes and has an unspecified resultgif. There may be at most one else-clause.

The following example will print out a message if one has arrived or arrives within 1000 time units:

(define primitive-message-event (make-event))

(select (primitive-message-event => (lambda (message) (event.clear! primitive-message-event) (write-line message))) ((make-timeout-event 1000) 'timed-out!))



Erik Rauch
Sat May 8 16:42:57 EDT 1999