> Date: Sat, 28 Jan 2023 02:36:03 +0000 > From: Glenn Takanishi <gl...@neuralmachines.com> > > I using Mit-scheme 12.1 trying to use the program "thread.scm" in the > runtime directory. This program has the procedure "make-thread" in it. > But when I tried to run a test with the following program below, it > failed with the error message "Unbound variable: make-thread". > > [...] > ;; (load "/usr/local/mit-scheme/lib/mit-scheme/runtime/thread.scm") > [...] > > I wondering why this threads extension is not documented as the > thread.scm program looks good. I'd like to see how this runs. > > Can you tell me what I need to add to the test code above to get it to > run.
This file, thread.scm, is not an extension -- it's a built-in part of MIT Scheme. The make-thread procedure in it is purely internal, not for use of the API. To start a thread, use create-thread, like this: (create-thread #f (lambda () (sleep-current-thread 1000) (write-line 'hello-world))) Longer example with a mutex and condition variable: (define m (make-thread-mutex)) (define c (make-condition-variable)) (define done? #f) (define t (create-thread #f (lambda () (sleep-current-thread 1000) (with-thread-mutex-lock m (lambda () (set! done? #t) (condition-variable-broadcast! c)))))) (with-thread-mutex-lock m (lambda () (do () (done?) (condition-variable-wait! c m)))) FYI: The threads do not actually run in parallel at the moment. They are time-shared. So they are useful for doing I/O asynchronously, but not for parallelizing computation. (This might change some day.)