cs: avoid race with GC in (current-memory-use 'cumulative)

Thanks to Alex Harsanyi for reporting the problem.
This commit is contained in:
Matthew Flatt 2020-12-15 19:09:56 -07:00
parent 4590c51d32
commit bcfbf2249e
2 changed files with 19 additions and 1 deletions

View File

@ -0,0 +1,17 @@
#lang racket/base
;; Check whether `(current-memory-use 'cumulative)` is always increasing
(define (work n)
(length (let loop ([n n])
(if (zero? n)
'()
(cons (make-vector n) (loop (sub1 n)))))))
(let loop ([n 20000] [u (current-memory-use 'cumulative)])
(unless (zero? n)
(work (random 1000))
(let ([u2 (current-memory-use 'cumulative)])
(if (u2 . < . u)
(error "oops")
(loop (sub1 n) u2)))))

View File

@ -190,7 +190,8 @@
[(mode)
(cond
[(not mode) (bytes-allocated)]
[(eq? mode 'cumulative) (+ (bytes-deallocated) (bytes-allocated))]
[(eq? mode 'cumulative) (with-interrupts-disabled
(+ (bytes-deallocated) (bytes-allocated)))]
;; must be a custodian; hook is reposnsible for complaining if not
[else (custodian-memory-use mode (bytes-allocated))])]))