unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* libguile thread safety
@ 2014-01-03 23:34 Chris Vine
  2014-01-04  0:00 ` Ludovic Courtès
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Chris Vine @ 2014-01-03 23:34 UTC (permalink / raw)
  To: guile-user

Hi,

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;
}

However, it prints "Hello" correctly if only one thread is started.
It seems that scm_with_guile() is not thread safe in the form used
above. However the following suggest that it should be:

http://www.gnu.org/software/guile/manual/html_node/Multi_002dThreading.html#Multi_002dThreading
http://www.gnu.org/software/guile/manual/html_node/Initialization.html#Initialization

I am clearly doing something wrong, which is probably obvious to
others. Can anyone help me with this?  Perhaps I have to serialize use
of scm_with_guile() notwithstanding what is said in the documentation,
but if so it will be disappointing for the use to which I was hoping to
put it.

Chris



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2014-03-18 19:32 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-03 23:34 libguile thread safety Chris Vine
2014-01-04  0:00 ` Ludovic Courtès
2014-01-04 17:19   ` Chris Vine
2014-01-04  0:08 ` Panicz Maciej Godek
2014-01-04  0:22   ` Chris Vine
2014-01-04  0:56     ` Panicz Maciej Godek
2014-01-04  1:22       ` Panicz Maciej Godek
2014-01-04  9:39         ` Chris Vine
2014-01-04 21:28           ` Mark H Weaver
2014-01-04  1:59 ` Mark H Weaver
2014-01-04  9:50   ` Chris Vine
2014-01-04 12:44   ` Chris Vine
2014-01-04 15:01     ` Panicz Maciej Godek
2014-01-04 17:16       ` Chris Vine
2014-01-04 19:37       ` Mark H Weaver
2014-01-04 21:01         ` Chris Vine
2014-01-04 22:43           ` Panicz Maciej Godek
2014-01-04 23:31             ` Chris Vine
2014-01-05 13:15               ` Panicz Maciej Godek
2014-01-05 17:37                 ` Mark H Weaver
2014-03-18 10:49                   ` Chris Vine
2014-03-18 15:22                     ` Mark H Weaver
2014-03-18 19:32                       ` Chris Vine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).