[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
17.1.3 Condition Variables
- SRFI-18 function: condition-variable? obj
- SRFI-18 function: make-condition-variable [name]
- SRFI-18 function: condition-variable-name cv
- SRFI-18 function: condition-variable-specific cv
- SRFI-18 function: condition-variable-specific-set! cv obj
- Bigloo function: condition-variable-wait! cv mutex [timeout]
- SRFI-18 function: condition-variable-signal! cv
- SRFI-18 function: condition-variable-broadcast! cv
(let ((res 0)) (define (make-semaphore n) (vector n (make-mutex) (make-condition-variable))) (define (semaphore-wait! sema) (mutex-lock! (vector-ref sema 1)) (let ((n (vector-ref sema 0))) (if (> n 0) (begin (vector-set! sema 0 (- n 1)) (mutex-unlock! (vector-ref sema 1))) (begin (condition-variable-wait! (vector-ref sema 2) (vector-ref sema 1)) (mutex-unlock! (vector-ref sema 1)) (semaphore-wait! sema))))) (define (semaphore-signal-by! sema increment) (mutex-lock! (vector-ref sema 1)) (let ((n (+ (vector-ref sema 0) increment))) (vector-set! sema 0 n) (if (> n 0) (condition-variable-broadcast! (vector-ref sema 2))) (mutex-unlock! (vector-ref sema 1)))) (let ((sema (make-semaphore 10))) (let ((t1 (thread-start! (instantiate::thread (body (lambda () (semaphore-wait! sema) (set! res (current-time))))))) (t2 (thread-start! (instantiate::thread (body (lambda () (let loop ((n 10)) (if (> n 0) (begin (semaphore-signal-by! sema 1) (thread-yield!) (loop (- n 1))))))))))) (scheduler-start!) res))) ⇒ 2
This document was generated on March 31, 2014 using texi2html 5.0.