guile-user
[Top][All Lists]
Advanced

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

Re: libguile thread safety


From: Panicz Maciej Godek
Subject: Re: libguile thread safety
Date: Sat, 4 Jan 2014 02:22:11 +0100

I concluded that this might be a solution. I tested it with 2.0.5 from
ubuntu repository. I had to add GC_allow_register_threads (and link
against gc, accordingly), because otherwise the program aborted with
the message "Threads explicit registering is not previously enabled"
whenever it attempted to create a thread.

For some reason the initialization routine needs to call
scm_c_eval_string; otherwise it doesn't help.

The solution doesn't fill me with joy, but I hope it works for you

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

void *do_nothing(void *unused) {
  scm_c_eval_string("(noop)");
  return NULL;
}

int main () {
  pthread_t thread1;
  pthread_t thread2;

  GC_allow_register_threads();

  scm_with_guile(do_nothing, NULL);

  pthread_create (&thread1, NULL, thread_func, NULL);
  pthread_create (&thread2, NULL, thread_func, NULL);

  pthread_join (thread1, NULL);
  pthread_join (thread2, NULL);

  return 0;
}



reply via email to

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