Functions exported by the threads structure

(SPAWN thunk)
(SPAWN thunk name)
Create and schedule a new thread that will execute . The optional name is used when printing the thread.

Let other threads run for a while.

(SLEEP time)
Sleep for
Kill the current thread.

(THREAD? thing)
#T if thing is a thread, #F otherwise.

(THREAD-NAME thread)
(THREAD-UID thread)
For printing debugging information.

Functions exported by the locks structure

(MAKE-LOCK) => lock
Locks are semaphores.

Functions exported by the placeholders structure

(MAKE-PLACEHOLDER) => placeholder
(PLACEHOLDER-VALUE placeholder) => value of placeholder
(PLACEHOLDER-SET! placeholder value)
(PLACEHOLDER? thing) => #t or #f
Attempts to reference a placeholder before it has been set cause the referencing thread to block. Setting a placeholder to two different values is an error. (Previous versions of Scheme 48 called these `condition variables', which turn out to be somewhat different.)

Threads and the command interpreter

Each level of the command interpreter has its own set of active threads. Moving to a new level, for example when an error occurs, halts all threads belonging to the previous level. Resuming the a level causes its associated threads to continue running.

The ,threads command inspects the threads running in the stopped command level.

    > ,open threads
    > (define (foo) (sleep 1000) (display "Hi") (newline) (foo))
    > (spawn foo 'my-thread)
    > Hi
    (begin (sleep 10000) (display "Done") (newline))
    Interrupt: keyboard
    1> (sleep 5000)
    ; note that the Hi thread doesn't run in this command level
    1> ,proceed 0
    ; but it resumes when we resume this level
    > Hi
    Interrupt: keyboard
    1> ,threads
    '(#{Thread 28 my-thread} #{Thread 27 command-loop})
     [0] '#{Thread 28 my-thread}
     [1] '#{Thread 27 command-loop}


Ownership, Maintenance and Disclaimers

Scheme48 Manual Top Page

Envision Manual Top Page

Last modified