From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mathieu Othacehe Subject: Re: (guix git) and guile-git finalizers. Date: Tue, 13 Jun 2017 18:39:12 +0200 Message-ID: <87o9tr3kr3.fsf@gmail.com> References: <86h8zliddr.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKoqe-0007uo-I9 for guix-devel@gnu.org; Tue, 13 Jun 2017 12:39:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKoqa-0003tr-IJ for guix-devel@gnu.org; Tue, 13 Jun 2017 12:39:20 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:35298) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dKoqa-0003tT-BO for guix-devel@gnu.org; Tue, 13 Jun 2017 12:39:16 -0400 Received: by mail-wr0-x241.google.com with SMTP id z45so954941wrb.2 for ; Tue, 13 Jun 2017 09:39:14 -0700 (PDT) In-reply-to: List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Andy Wingo Cc: guix-devel , Amirouche Hi Andy, > Nice sleuthing! Thanks :) > > If you want to manually handle finalization at 'safe' points from > Scheme, guardians are the things to use. Add your "finalizable" object > to a guardian, and periodically "pump" the guardian to see if anything > is finalizable; you can run the finalizer there. So, the idea would be to create a global guardian with : --8<---------------cut here---------------start------------->8--- (define pointer-guardian (make-guardian)) --8<---------------cut here---------------end--------------->8--- and replace those kind of functions : --8<---------------cut here---------------start------------->8--- (define (pointer->commit! pointer) (set-pointer-finalizer! pointer %commit-free) (pointer->commit pointer)) --8<---------------cut here---------------end--------------->8--- by, --8<---------------cut here---------------start------------->8--- (define (pointer->commit! pointer) (pointer-guardian pointer) (pointer->commit pointer)) --8<---------------cut here---------------end--------------->8--- But then, at shutdown, when I'll call (pointer-guardian) to get the list of free-able pointers, how can I know that %commit-free has to be called on commit pointers, %reference-free on reference pointers, ... ? Thanks, Mathieu