Suppose I have a multithreaded C program. Isn't the guile environment supposed
to be shared amongst all threads ? That's what I understood from reading the
docs anyway.
Yet this simple exemple shows the opposite (see the 3 attached files).
So am I supposed to source my global scheme definitions in all threads ?
#include <unistd.h>
#include <pthread.h>
#include <libguile.h>
static void *load_file_with_guile(void *filename)
{
scm_c_primitive_load((char *)filename);
return NULL;
}
static void *hug_me(void *str)
{
scm_c_eval_string(str);
}
static void *thread_hugme(void *dummy)
{
//scm_with_guile(load_file_with_guile, "bug.scm");
scm_with_guile(hug_me, "(hug 2)");
return NULL;
}
int main(void) {
scm_with_guile(load_file_with_guile, "bug.scm");
scm_with_guile(hug_me, "(hug 1)");
pthread_t thread;
pthread_create(&thread, NULL, thread_hugme, NULL);
pthread_join(thread, NULL);
return 0;
}
(use-modules (ice-9 format))
(define (hug x) (format #t "HUG ~a !\n" x))
CFLAGS += $(shell guile-config compile)
LDLIBS += $(shell guile-config link) -lpthread
all: bug