From: Kevin Ryde <user42@zip.com.au>
To: guile-devel@gnu.org
Subject: port-for-each vs lazy sweep
Date: Sun, 19 Aug 2007 11:22:27 +1000 [thread overview]
Message-ID: <878x88pbcc.fsf@zip.com.au> (raw)
I've struck, in 1.8, port-for-each passing a freed cell to its iterator
func. Eg. "guile -s foo.scm" on
(define lst '())
(gc) (gc) (gc)
(make-list 1000)
(open-input-file "/etc/passwd")
(make-list 1000)
(open-input-file "/etc/passwd")
(make-list 1000)
(open-input-file "/etc/passwd")
(make-list 1000)
(open-input-file "/etc/passwd")
(gc)
(port-for-each (lambda (port)
(set! lst (cons port lst))))
(gc) (gc) (gc)
(display lst) (newline)
gives
(#<freed cell 0xb7c3bd20; GC missed a reference> #<freed cell 0xb7c3ed78; GC missed a reference> #<freed cell 0xb7c41558; GC missed a reference> #<input: port-weak.scm 5> #<output: standard error /dev/pts/2> #<output: standard output /dev/pts/2> #<input: standard input /dev/pts/2> #<input-output: string 805d030> #<output: string 805cf70>)
I suspect the opened ports are correctly found to be unused and left
unmarked by the gc, but they remain in the port table. port-for-each
then passes them to its func and a little later the sweep gets to them
and they turn into freed cells. (I noticed this when printing ports
from within port-for-each as a diagnostic.)
I suppose either port-for-each should ignore ports which are unmarked
and unswept; or the gc should sweep the port table entries immediately
instead of lazily. Neither sounds pretty, but the latter might be safer
than letting zombies remain in the port table. I suspect for instance
`flush-all' could suffer the same problem if it does a callback to a
soft port flush function (or a C code ptob flush func if that somehow
provoked some sweeping).
(This got me wondering why there's a port table anyway, instead of
independent objects with say a weak hash table for the "list of all
ports" needed by port-for-each and flush-all. Historical reasons I
suppose.)
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
next reply other threads:[~2007-08-19 1:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-19 1:22 Kevin Ryde [this message]
2007-08-20 8:42 ` port-for-each vs lazy sweep Ludovic Courtès
2007-08-21 0:30 ` Kevin Ryde
2007-08-23 0:32 ` Kevin Ryde
2007-08-23 7:25 ` Ludovic Courtès
2007-08-25 18:57 ` Han-Wen Nienhuys
2007-08-25 22:20 ` Han-Wen Nienhuys
2007-08-26 17:04 ` Ludovic Courtès
2007-08-26 17:16 ` Han-Wen Nienhuys
2007-08-26 17:36 ` Ludovic Courtès
2007-08-26 18:06 ` Han-Wen Nienhuys
2007-09-03 17:20 ` Ludovic Courtès
2007-09-03 19:34 ` Han-Wen Nienhuys
2007-09-04 9:08 ` Ludovic Courtès
2007-10-01 20:23 ` Ludovic Courtès
2007-10-27 15:07 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878x88pbcc.fsf@zip.com.au \
--to=user42@zip.com.au \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).