[gambit-list] is this a problem in my code?
alvaro.castro.castilla at gmail.com
Thu Oct 4 08:24:47 EDT 2012
I'm trying to figure out a parallel implementation of for-each (I'm going
to use it for spawning system processes mostly).
Anyway, the problem is like this: If I use any kind of recursion inside the
thread created in the (new-thread) proc, I get this error:
*** ERROR IN for-each -- Uncaught exception: #<type-exception #31>
(thread-join! '#<thread #32>)
As soon as I remove the call to (recur) (it would happen also with letrec
for instance), it works as expected. I really don't understand how internal
recursion in the thread could yield this error.
Thanks for your help
(define (parallel-for-each f l #!key (max-thread-number 2))
(let* ((pending-jobs l)
(available-jobs? (lambda ()
(let ((more? (not (null? pending-jobs))))
(next-element (lambda ()
(let ((next (car pending-jobs)))
(set! pending-jobs (cdr pending-jobs))
(add-to-results! (lambda (r)
(set! results (cons r results))
(let recur ()
(add-to-results! (f (next-element)))
(let do-times ((n 0)
(if (< n max-thread-number)
(do-times (++ n)
(cons (new-thread) thread-pool))
(for-each thread-join! thread-pool))))
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Gambit-list