[plt-scheme] capturing output from different threads

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Mar 6 18:20:07 EST 2008

At Thu, 06 Mar 2008 21:17:50 +0000, Dave Griffiths wrote:
> Scheme_Object *outport=NULL;
> Scheme_Object *errport=NULL;
> 
> void interpret(Scheme_Env *e, char *code)
> {
> 	mz_jmp_buf * volatile save=NULL, fresh;
> 	char *msg=NULL;
> 	
>    	MZ_GC_DECL_REG(5);
>     	MZ_GC_VAR_IN_REG(0, outport);
>     	MZ_GC_VAR_IN_REG(1, errport);

Use MZ_GC_VAR_IN_REG() for stack-allocated locations, only.

Use MZ_REGISTER_STATIC() to register a static location. A static
variable should be registered only once, and MZ_GC_UNREG() doesn't
remove the registration (i.e,. it's completely indpendent of registered
stack bindings).

Matthew

----------------------------------------

--- orig.c	2008-03-06 16:18:44.000000000 -0700
+++ ex.c	2008-03-06 16:18:40.000000000 -0700
@@ -9,12 +9,10 @@
 	mz_jmp_buf * volatile save=NULL, fresh;
 	char *msg=NULL;
 	
-   	MZ_GC_DECL_REG(5);
-    	MZ_GC_VAR_IN_REG(0, outport);
-    	MZ_GC_VAR_IN_REG(1, errport);
-    	MZ_GC_VAR_IN_REG(2, e);
-    	MZ_GC_VAR_IN_REG(3, msg);
-	MZ_GC_VAR_IN_REG(4, save);
+   	MZ_GC_DECL_REG(3);
+    	MZ_GC_VAR_IN_REG(0, e);
+    	MZ_GC_VAR_IN_REG(1, msg);
+	MZ_GC_VAR_IN_REG(2, save);
     	MZ_GC_REG();
 	
 	save = scheme_current_thread->error_buf;
@@ -47,15 +45,16 @@
 	Scheme_Env *e = NULL;
 	Scheme_Config *config = NULL;
 
-	MZ_GC_DECL_REG(4);
+	MZ_GC_DECL_REG(2);
 	MZ_GC_VAR_IN_REG(0, e);
-	MZ_GC_VAR_IN_REG(1, outport);
-	MZ_GC_VAR_IN_REG(2, errport);
-	MZ_GC_VAR_IN_REG(3, config);
+	MZ_GC_VAR_IN_REG(1, config);
 	scheme_set_stack_base( &__gc_var_stack__, 1);
  	MZ_GC_REG();
 	e = scheme_basic_env();
 
+        MZ_REGISTER_STATIC(outport);
+        MZ_REGISTER_STATIC(errport);
+
 	outport = scheme_make_byte_string_output_port();
 	errport = scheme_make_byte_string_output_port();
 	config = scheme_current_config();



Posted on the users mailing list.