Welcome to the CHICKEN Scheme pasting service
m + cv example pasted by evhan on Mon Jun 22 07:51:27 2020
(import (srfi 18)) (define m (make-mutex)) (define c (make-condition-variable)) (define countdown 5) (define j (thread-start! (lambda () (let loop () (mutex-lock! m) (if (zero? countdown) (print "blastoff!") (begin (mutex-unlock! m c) (loop))))))) (do () ((zero? countdown)) (print "blastoff in " countdown "...") (thread-sleep! 1) (set! countdown (sub1 countdown)) (condition-variable-signal! c)) (thread-join! j)
Start and Wait (condition variables) added by tolstoy on Mon Jun 22 07:54:52 2020
(import (chicken process signal)) (import srfi-18) (define (make-handler cv msg) (lambda (signum) (print msg " signal") (condition-variable-specific-set! cv 'break) (condition-variable-signal! cv))) (let [(m (make-mutex)) (cv (make-condition-variable))] (condition-variable-specific-set! cv 'hold) (set-signal-handler! signal/int (make-handler cv "INT")) (thread-start! (lambda () (sleep 4) (condition-variable-specific-set! cv 'break) (condition-variable-signal! cv))) (let loop () (print "+ loop") (mutex-lock! m) (print "+ unlock") (mutex-unlock! m cv) (when (equal? 'hold (condition-variable-specific cv)) (loop)) (print "done")))