Mark H Weaver <m...@netris.org> skribis: > From dadcb1512569c1be039fc75f0a2967e370939e42 Mon Sep 17 00:00:00 2001 > From: Mark H Weaver <m...@netris.org> > Date: Thu, 28 Feb 2013 17:56:58 -0500 > Subject: [PATCH] Fix thread-unsafe lazy initializations. > > * libguile/debug.c (scm_local_eval): > libguile/ports.c (scm_current_warning_port): > libguile/strports.c (scm_eval_string_in_module): Perform > lazy-initialization while holding a mutex. Use SCM_UNDEFINED as the > uninitialized value. Use 'scm_c_*_variable'. > > * doc/ref/api-modules.texi (Accessing Modules from C): Fix > 'my_eval_string' example to be thread-safe.
Looks good to me. > --- a/doc/ref/api-modules.texi > +++ b/doc/ref/api-modules.texi > @@ -942,14 +942,15 @@ the @var{name} is not bound in the module, signals an > error. Returns a > variable, always. > > @example > -SCM my_eval_string (SCM str) > -@{ > - static SCM eval_string_var = SCM_BOOL_F; > +static SCM eval_string_var; > > - if (scm_is_false (eval_string_var)) > - eval_string_var = > - scm_c_public_lookup ("ice-9 eval-string", "eval-string"); > +void my_init (void) > +@{ > + eval_string_var = scm_c_public_lookup ("ice-9 eval-string", "eval-string"); > +@} > > +SCM my_eval_string (SCM str) > +@{ > return scm_call_1 (scm_variable_ref (eval_string_var), str); > @} > @end example The doc should say something about ‘my_init’, and perhaps mention locking? Ludo’.