From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041111 Firefox/1.0 Description of problem: I've started such code: (define finite-loop (lambda (n m mutex) (lock-mutex mutex) (cond ((not (= 0 n)) (yield) (display m) (display ", ") (display n) (newline) (unlock-mutex mutex) (finite-loop (- n 1) m mutex))) (unlock-mutex mutex) )) (define thread-error-handler (lambda (tag . args) (display tag) (display " ") (display args) (newline) )) (define thread1 (let* ( (mutex (make-mutex)) (thread-function (lambda () (finite-loop 1000000 1 mutex))) ) (cons (call-with-new-thread thread-function thread-error-handler) mutex) ) ) (display thread1) (newline) (finite-loop 100 2 (cdr thread1)) (join-thread (car thread1)) After a while stack overflow inside of the finite-loop function occurs. When I remove mutex locking/unlocking functions program is working properly. Version-Release number of selected component (if applicable): guile-1.6.4-14 How reproducible: Always Steps to Reproduce: 1. Create file threads-with-mutex.scm 2. Paste program shown above into that file 3. run: guile -s threads-with-mutex.scm Actual Results: After a while you may see something like that: 1, 9012 1, 9011 1, 9010 stack-overflow (#f Stack overflow #f #f) Expected Results: Further program execution Additional info: The workaround is to use 'do' iteration instead of recursion: (define finite-loop (lambda (n m mutex) (do ((i n (- i 1))) ((= 0 i)) (lock-mutex mutex) (yield) (display m) (display " ") (display i) (newline) (unlock-mutex mutex) ) )) However, iteration is not always a solution! That makes mutexes dangerous to use...
I've just found another workaround. The problem is that mutex should be unlocked insite the cond expression: (define finite-loop (lambda (n m mutex) (lock-mutex mutex) (cond ((not (= 0 n)) (yield) (display m) (display ", ") (display n) (newline) (unlock-mutex mutex) (finite-loop (- n 1) m mutex) ) (else (unlock-mutex mutex)) ) )) But let someone tell me which scheme rule says that previous code was wrong?!
Maybe you get one more mutex for each iteration run and they are possibly put on the internal guile stack and therefore cause in one case an overflow but not in the other. But this is just a wield speculative guess. I'm closing this bug as it's really most likely something very specific and internal of guile and should rather be handled and fixed properly by the upstream folks. Read ya, Phil