racket/collects/tests/mzscheme/benchmarks/shootout/thread-ring.ss
Matthew Flatt 55a44ae5bc shootout benchmarks
svn: r10840
2008-07-19 14:27:00 +00:00

26 lines
648 B
Scheme

;; Uses PLT Scheme threads
#lang scheme/base
(require scheme/cmdline)
;; Each thread runs this loop:
(define (run id next)
(let ([v (thread-receive)])
(cond
[(zero? v) ;; Done
(printf "~a\n" id)
(exit)]
[else ;; Keep going
(thread-send next (sub1 v))
(run id next)])))
(let ([n (command-line #:args (n) (string->number n))])
;; The original thread is #503. Create the rest:
(let ([t1 (for/fold ([next (current-thread)])
([id (in-range 502 0 -1)])
(thread (lambda () (run id next))))])
;; Start:
(thread-send t1 n)
(run 503 t1)))