[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
reentrant port table stuff
From: |
Chris Cramer |
Subject: |
reentrant port table stuff |
Date: |
Thu, 26 Jul 2001 14:50:08 -0500 |
User-agent: |
Mutt/1.2.5i |
I'm using the stable CVS branch of Guile. This program eventually
segfaults, because open-output-file and close-port (and open-file, etc)
are not reentrant:
(use-modules (ice-9 threads))
(define (child port)
(display "Hello" port)
(newline port))
(define (create-child)
(begin-thread
(let ((port (open-output-file "/dev/null")))
(child port)
(close-port port))))
(define (test-threads . ignored)
(let loop ((i 0))
(create-child)
(display i) (newline)
(loop (+ i 1))))
This patch fixes it, by deferring interrupts in scm_add_to_port_table
and scm_remove_from_port_table:
Index: libguile/ports.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/ports.c,v
retrieving revision 1.153.2.1
diff -u -r1.153.2.1 ports.c
--- libguile/ports.c 2001/07/09 07:31:04 1.153.2.1
+++ libguile/ports.c 2001/07/26 19:41:05
@@ -438,6 +438,7 @@
{
scm_t_port *entry;
+ SCM_DEFER_INTS;
if (scm_t_portable_size == scm_t_portable_room)
{
/* initial malloc is in gc.c. this doesn't use scm_must_malloc etc.,
@@ -466,6 +467,7 @@
scm_t_portable[scm_t_portable_size] = entry;
scm_t_portable_size++;
+ SCM_ALLOW_INTS;
return entry;
}
@@ -482,6 +484,7 @@
if (i >= scm_t_portable_size)
SCM_MISC_ERROR ("Port not in table: ~S", scm_list_1 (port));
+ SCM_DEFER_INTS;
if (p->putback_buf)
scm_must_free (p->putback_buf);
scm_must_free (p);
@@ -494,6 +497,7 @@
}
SCM_SETPTAB_ENTRY (port, 0);
scm_t_portable_size--;
+ SCM_ALLOW_INTS;
}
#undef FUNC_NAME
--
C. Ray C. aka Christopher Cramer
address@hidden
http://www.pyro.net/~crayc/
- reentrant port table stuff,
Chris Cramer <=