-
-
Save endobson/6efdca16885162b51b76ab385e9afa5b to your computer and use it in GitHub Desktop.
Finalizers don't run reliably from other places
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(require | |
racket/place | |
ffi/unsafe | |
ffi/unsafe/alloc) | |
(define (other-place) | |
(place p | |
(define (f) (malloc 'raw (* 1024 1024 1024))) | |
(define port (current-output-port)) | |
(define (dealloc x) | |
(displayln 'dealloc-orig port) | |
(place-channel-put p 'dealloc) | |
(free x)) | |
(let ([v (((allocator dealloc) f))]) | |
(memset v 0 (* 1024 1024 1024)) | |
(place-channel-put p 'ready) | |
(displayln (ptr-ref v _int)) | |
(sync p) ;; 'msg | |
(place-channel-put p 'msg-response)) | |
(collect-garbage) | |
;; This sleep determines if the finalizer thread gets time to run | |
;(sleep 1) | |
(displayln 'exit))) | |
(define (run) | |
(define p (other-place)) | |
(displayln (sync p)) | |
(displayln (place-channel-put/get p 'msg)) | |
(displayln (sync p))) | |
(module+ main | |
(run)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment