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 17:19:12 +0000

On Sat, 04 Jan 2014 01:00:46 +0100
address@hidden (Ludovic Courtès) wrote:
> Chris Vine <address@hidden> skribis:
> 
> > 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:
> >
> > #include <libguile.h>
> > #include <pthread.h>
> >
> > void *guile_wrapper (void *data) {
> >   scm_c_eval_string ("(display \"Hello\n\")");
> >   return NULL;
> > }
> >
> > void *thread_func (void *data) {
> >   scm_with_guile (&guile_wrapper, NULL);
> >   return NULL;
> > }
> >
> > int main () {
> >   pthread_t thread1;
> >   pthread_t thread2;
> >
> >   pthread_create (&thread1, NULL, thread_func, NULL);
> >   pthread_create (&thread2, NULL, thread_func, NULL);
> >
> >   pthread_join (thread1, NULL);
> >   pthread_join (thread2, NULL);
> >   return 0;
> > }
> 
> This should work (but see below.)  In fact, this is what
> test-pthread-create-secondary.c tests (in Guile’s test suite.)
> 
> It may fail if libgc was built without pthread support, or if it’s an
> old version (older than 7.2alpha6).  Could you check that?
> 
> However, ports themselves are not thread-safe in 2.0, and the code
> above has several threads writing to the current output port, which
> is a problem.  When an application has several threads using the same
> port, it must do its own locking currently.

I am using gc-7.2d, and objdump -p shows that libgc.so.1 has a hard
linking dependency on libpthread, so it looks as if it is compiled with
thread support.  You will see from later postings that this problem can
be avoided by allowing one thread to initialize scm_with_guile() and
scm_c_eval_string() to completion before any others attempt to do so.

Chris



reply via email to

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