Threading

Arc supports multiple threads of execution. One useful application of threads is to run a long-running process in the "background", for instance Arc's web server:
arc> (thread (asv 8000))
#
arc>
ready to serve port 8000
See MzScheme's Threads for details of the threading model.

Threading

thread [body ...]
Creates and returns a new thread, which will last until the body terminates.
>(thread (+ 1 2) (+ 3 4))
#<thread>
>(type (thread (+ 1 2)))
thread
new-thread procedure
Creates and returns a new thread, which will last until procedureterminates. This was called thread in arc0.
>(new-thread (fn () (+ 1 2)))
#<thread>
break-thread thread
Triggers a break exception on a thread.
>(let th (thread (sleep 2))
  (break-thread th))
user break
kill-thread thread
Terminates the specified thread immediately.
>(let th (thread (sleep 100))
    (kill-thread th)
    (dead th))
t
sleep secs
Causes the current thread to sleep for at least the specified time.
>(sleep 0.1)
nil
dead thread
Predicate to test if a thread has terminated.
>(let th (thread (sleep 1))
  (prn (dead th)) (sleep 2) (prn (dead th)))
nil
t

t

Copyright 2008 Ken Shirriff.