guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: libguile thread safety


From: Chris Vine
Subject: Re: libguile thread safety
Date: Sat, 4 Jan 2014 12:44:59 +0000

On Fri, 03 Jan 2014 20:59:16 -0500
Mark H Weaver <address@hidden> wrote:
> Chris Vine <address@hidden> writes:
> > I am having problems using libguile in a multi-threaded environment,
> > which boils down to the following small test case, which fails with
> > a segmentation fault with guile-2.0.9:
> 
> I've recently noticed that the module loading process in Guile is not
> thread safe.  I hope to fix this in the next month or two, but for now
> I'd recommend that one thread should initialize Guile and load the
> modules that will be needed, before allowing multiple threads to enter
> Guile mode.

There is something even more bizarre than as reported in the exchange
with Maciej.  The further test case below prints:

  Hello
  20
  20

I would have expected:

  Hello
  10
  20

It seems as if top level variables in code evaluated by scm_c_eval_string()
are shared between concurrently running threads.  Is this really the
intended behaviour (it is a significant and unexpected usability
restriction)?  Maciej (I hope that is your first name) can you reproduce
this?

Chris


#include <libguile.h>
#include <pthread.h>

void *guile_wrapper1 (void *data) {
  scm_c_eval_string("(display \"Hello\n\")");
  return NULL;
}

void *guile_wrapper2 (void *data) {
  scm_c_eval_string("(define val 10) (usleep 200000)(display val)(newline)");
  return NULL;
}

void *guile_wrapper3 (void *data) {
  scm_c_eval_string("(usleep 100000) (define val 20) (display val)(newline)");
  return NULL;
}

void *thread_func1 (void *data) {
  scm_with_guile(&guile_wrapper1, NULL);
  return NULL;
}

void *thread_func2 (void *data) {
  scm_with_guile(&guile_wrapper2, NULL);
  return NULL;
}

void *thread_func3 (void *data) {
  scm_with_guile(&guile_wrapper3, NULL);
  return NULL;
}

int main () {
  pthread_t thread1;
  pthread_t thread2;
  pthread_t thread3;

  pthread_create(&thread1, NULL, thread_func1, NULL);
  pthread_join(thread1, NULL);

  pthread_create(&thread2, NULL, thread_func2, NULL);
  pthread_create(&thread3, NULL, thread_func3, NULL);
  pthread_join(thread2, NULL);
  pthread_join(thread3, NULL);
  return 0;
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]