123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- (define-module (ice-9 threads))
- (define-public (%thread-handler tag . args)
- (fluid-set! the-last-stack #f)
- (unmask-signals)
- (let ((n (length args))
- (p (current-error-port)))
- (display "In thread:" p)
- (newline p)
- (if (>= n 3)
- (display-error #f
- p
- (car args)
- (cadr args)
- (caddr args)
- (if (= n 4)
- (cadddr args)
- '()))
- (begin
- (display "uncaught throw to " p)
- (display tag p)
- (display ": " p)
- (display args p)
- (newline p)))))
- (defmacro-public make-thread (fn . args)
- `(call-with-new-thread
- (lambda ()
- (,fn ,@args))
- %thread-handler))
- (defmacro-public begin-thread (first . thunk)
- `(call-with-new-thread
- (lambda ()
- (begin
- ,first ,@thunk))
- %thread-handler))
- (defmacro-public with-mutex (m . thunk)
- `(dynamic-wind
- (lambda () (lock-mutex ,m))
- (lambda () (begin ,@thunk))
- (lambda () (unlock-mutex ,m))))
- (defmacro-public monitor (first . thunk)
- `(with-mutex ,(make-mutex)
- (begin
- ,first ,@thunk)))
|