;karlheg@inetarena.com (Karl M. Hegbloom) writes: ;> Does anyone have any code that shows how to use threads in Guile ;> scheme? I would like to test my build, and also to see how to make ;> threads. ;Here's a small example: ;---------------------------------------------------------------------- (define c 0) (define q #f) (define (start) (set! q #f) (begin-thread (let loop () (if (not q) (begin (set! c (1+ c)) (select () () () 0 10000) (loop)))))) (define (stop) (set! q #t)) ;---------------------------------------------------------------------- ;Type (start) to spawn the thread. ;Look at the counter by evaluating `c'. ;Type (stop) to kill the thread. ;Here's an example using the newly released guile-tcltk snapshot: ;---------------------------------------------------------------------- ;(use-modules (tcltk tcltk)) ;(tk-main-window "Hand" "200x200") ;(define c (canvas #f)) ;(pack c) ;(define pi 3.1416) ;(define x0 100) ;(define y0 100) ;(define (x1 a) (+ x0 (* 100 ($cos a)))) ;(define (y1 a) (- x0 (* 100 ($sin a)))) ;(define angle (/ pi 2)) ;(define delta 0.005) ;(define hand (c 'create 'line x0 y0 (x1 angle) (y1 angle))) ;(define moving? #t) ;(define (hand-loop) ; (if moving? ; (begin ; (set! angle (+ angle delta)) ; (c 'coords hand x0 y0 (x1 angle) (y1 angle)) ; (select () () () 0 5000) ; (hand-loop)))) ;(define mu (make-mutex)) ;(define cv (make-condition-variable)) ;(begin-thread ; (let loop () ; (set! moving? #t) ; (hand-loop) ; (wait-condition-variable cv mu) ; (loop))) ;(define (start) ; (signal-condition-variable cv)) ;(define (stop) ; (set! moving? #f)) ;---------------------------------------------------------------------- ;/mdj