#lang racket (require "ThreadsV3.rkt") (define make-counter (lambda (init incr) (let ( (counter init) ) (list (lambda () counter) ; return the current value (lambda () (set! counter init) ) ; reset to the initial value (lambda () (set! counter (+ counter incr)) counter) ; increment and return the current value (lambda () (set! counter (- counter incr)) counter) ; decrement and return the current value )))) (define counter (make-counter 0 1)) (define thread-num (first counter)) (define thread-reset (second counter)) (define ++thread-num (third counter)) (define --thread-num (fourth counter)) ; parallel search of a tree ; thread definer that returns a function that searches the current ; list for a target token. (define def-p (lambda (T token id) (lambda () (display (list "thread " id " on " T " ")) (newline) (if (list? T) (if (null? T) '() ; T is a list, spawn a thread for each element of list, then yield (begin (map (lambda (e) (create-thread (def-p e token (++thread-num) )) ) T ) (yield) ) ) ; T is an atom, see if it matches token (begin ;(display (queue-get)) (display " ") (if (eq? T token) (display "match") (display "mismatch")) (newline) ) ) ) ) ) (define tree '( 1 2 1 ( 3 4 1 ( 2 1 ) 1 2 ) 4 (4 3 2 1 ))) (scheduler-init) (thread-reset) (create-thread (def-p tree 1 (thread-num) )) (scheduler-start)