From f57ea23ac8e1436f37ceeda3ea8625243c20e645 Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Thu, 28 Feb 2013 17:56:58 -0500 Subject: 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. --- doc/ref/api-modules.texi | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'doc/ref/api-modules.texi') diff --git a/doc/ref/api-modules.texi b/doc/ref/api-modules.texi index b9befc00c..47b81601b 100644 --- a/doc/ref/api-modules.texi +++ b/doc/ref/api-modules.texi @@ -945,14 +945,18 @@ 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"); +/* NOTE: It is important that the call to 'my_init' + happens-before all calls to 'my_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 -- cgit v1.2.3