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
|
||||
(require ffi/unsafe/os-thread
|
||||
(require ffi/unsafe
|
||||
ffi/unsafe/os-thread
|
||||
ffi/unsafe/os-async-channel)
|
||||
|
||||
(when (os-thread-enabled?)
|
||||
|
@ -37,5 +38,25 @@
|
|||
(printf "Done in ~a gets\n" steps)]
|
||||
[else
|
||||
(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)))])
|
||||
(thunk)
|
||||
(error #f "error expected")))
|
||||
(let ([g (make-guardian)])
|
||||
(let ([g (make-guardian #t)])
|
||||
(g (make-mutex))
|
||||
(collect)
|
||||
(let ([m (g)])
|
||||
|
|
|
@ -1952,8 +1952,8 @@
|
|||
(condition-guardian c)
|
||||
c)))
|
||||
|
||||
(define mutex-guardian (make-guardian))
|
||||
(define condition-guardian (make-guardian))
|
||||
(define mutex-guardian (make-guardian #t))
|
||||
(define condition-guardian (make-guardian #t))
|
||||
|
||||
(set! fork-thread
|
||||
(lambda (t)
|
||||
|
|
Loading…
Reference in New Issue
Block a user