Chez Scheme: use an ordered finalizer for mutexes and condition variables
That way, a mutex or conditional variable can be referenced by something else that has a finalizer and that might use the mutex or condition variable. Closes #3842
This commit is contained in:
parent
87fd43b1e5
commit
0b8ea67bb3
|
@ -1,5 +1,6 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
(require ffi/unsafe/os-thread
|
(require ffi/unsafe
|
||||||
|
ffi/unsafe/os-thread
|
||||||
ffi/unsafe/os-async-channel)
|
ffi/unsafe/os-async-channel)
|
||||||
|
|
||||||
(when (os-thread-enabled?)
|
(when (os-thread-enabled?)
|
||||||
|
@ -37,5 +38,25 @@
|
||||||
(printf "Done in ~a gets\n" steps)]
|
(printf "Done in ~a gets\n" steps)]
|
||||||
[else
|
[else
|
||||||
(os-async-channel-put ch 0)
|
(os-async-channel-put ch 0)
|
||||||
(loop new-counter (add1 steps))]))))
|
(loop new-counter (add1 steps))])))
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
;; make sure an os-async-channel can be used in a finalizer
|
||||||
|
|
||||||
|
(define finalized? #f)
|
||||||
|
|
||||||
|
(let () ;; if `begin`, no problem
|
||||||
|
(define c (make-os-async-channel))
|
||||||
|
(register-finalizer (list c)
|
||||||
|
(lambda (cs)
|
||||||
|
(os-async-channel-put (car cs) #f)
|
||||||
|
(set! finalized? #t))))
|
||||||
|
|
||||||
|
(for ([i 100])
|
||||||
|
(unless finalized?
|
||||||
|
(sync (system-idle-evt))
|
||||||
|
(collect-garbage)))
|
||||||
|
|
||||||
|
(unless finalized?
|
||||||
|
(error "finalizer never called")))
|
||||||
|
|
|
@ -1457,7 +1457,7 @@
|
||||||
(format "~a is defunct" what)))])
|
(format "~a is defunct" what)))])
|
||||||
(thunk)
|
(thunk)
|
||||||
(error #f "error expected")))
|
(error #f "error expected")))
|
||||||
(let ([g (make-guardian)])
|
(let ([g (make-guardian #t)])
|
||||||
(g (make-mutex))
|
(g (make-mutex))
|
||||||
(collect)
|
(collect)
|
||||||
(let ([m (g)])
|
(let ([m (g)])
|
||||||
|
|
|
@ -1952,8 +1952,8 @@
|
||||||
(condition-guardian c)
|
(condition-guardian c)
|
||||||
c)))
|
c)))
|
||||||
|
|
||||||
(define mutex-guardian (make-guardian))
|
(define mutex-guardian (make-guardian #t))
|
||||||
(define condition-guardian (make-guardian))
|
(define condition-guardian (make-guardian #t))
|
||||||
|
|
||||||
(set! fork-thread
|
(set! fork-thread
|
||||||
(lambda (t)
|
(lambda (t)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user