(cond-expand (chicken-5 (import (chicken base)) (import (chicken gc)) (import (srfi 18))) (else (use srfi-18))) (define *mtx* (make-mutex)) (define threads (list (make-thread (lambda () (mutex-lock! *mtx*) ;; I actually wanted to do this: ;; (set-finalizer! (list 'foo) (lambda (_) ;; (when (mutex-lock! *mtx* 0) ;; ;; do stuff ;; (mutex-unlock! *mtx*)))) ;; But this causes the same error (set-finalizer! (list 'foo) (lambda (_) (mutex-lock! *mtx*))) (gc #t) (mutex-unlock! *mtx*) ; this can be removed )) (make-thread (lambda () (gc #t))))) (for-each thread-start! threads) (for-each thread-join! threads) (print "done") ;; $ csc gcloop.scm && ./gcloop -:g ;; [GC] 1 finalizer(s) pending (1 live) ;; [GC] queueing 1 finalizer(s) ;; [GC] level 1 gcs(minor) 3 gcs(major) 1 ;; [GC] stack 0x00007ffe4e9a9470 0x000000004ea9f920 0x00007ffe4eaa9470 ;; [GC] from 0x00007f250b100010 0x00007f250b140330 0x00007f250b180010 0x0000000000040320 ;; [GC] to 0x00007f250b181010 0x00007f250b181010 0x00007f250b201010 ;; [GC] 0 locatives (from 32) ;; [GC] 1 finalized item(s) still pending ;; [GC] level 1 gcs(minor) 0 gcs(major) 2 ;; [GC] stack 0x00007ffe4e9a9470 0x000000004eaa7120 0x00007ffe4eaa9470 ;; [GC] from 0x00007f250b181010 0x00007f250b1c16f0 0x00007f250b201010 0x00000000000406e0 ;; [GC] to 0x00007f250b100010 0x00007f250b100010 0x00007f250b180010 ;; [GC] 0 locatives (from 32) ;; [GC] 1 finalized item(s) still pending ;; [GC] level 1 gcs(minor) 0 gcs(major) 3 ;; [GC] stack 0x00007ffe4e9a9470 0x000000004eaa9140 0x00007ffe4eaa9470 ;; [GC] from 0x00007f250b100010 0x00007f250b1406f0 0x00007f250b180010 0x00000000000406e0 ;; [GC] to 0x00007f250b181010 0x00007f250b181010 0x00007f250b201010 ;; [GC] 0 locatives (from 32) ;; [GC] 1 finalized item(s) still pending ;; [GC] level 1 gcs(minor) 0 gcs(major) 4 ;; [GC] stack 0x00007ffe4e9a9470 0x000000004eaa9140 0x00007ffe4eaa9470 ;; [GC] from 0x00007f250b181010 0x00007f250b1c16f0 0x00007f250b201010 0x00000000000406e0 ;; [GC] to 0x00007f250b100010 0x00007f250b100010 0x00007f250b180010 ;; [GC] 0 locatives (from 32) ;; [GC] 1 finalized item(s) still pending ;; [GC] level 1 gcs(minor) 0 gcs(major) 5 ;; [GC] stack 0x00007ffe4e9a9470 0x000000004eaa9140 0x00007ffe4eaa9470 ;; [GC] from 0x00007f250b100010 0x00007f250b1406f0 0x00007f250b180010 0x00000000000406e0 ;; [GC] to 0x00007f250b181010 0x00007f250b181010 0x00007f250b201010 ;; [GC] 0 locatives (from 32) ;; [GC] 1 finalized item(s) still pending ;; [GC] level 1 gcs(minor) 0 gcs(major) 6 ;; [GC] stack 0x00007ffe4e9a9470 0x000000004eaa9140 0x00007ffe4eaa9470 ;; [GC] from 0x00007f250b181010 0x00007f250b1c16f0 0x00007f250b201010 0x00000000000406e0 ;; ...