unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Thread and guile environment
@ 2010-07-05  8:23 rixed
  2010-07-05 19:52 ` Neil Jerram
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: rixed @ 2010-07-05  8:23 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

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 ?



[-- Attachment #2: bug.c --]
[-- Type: text/plain, Size: 604 bytes --]

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

[-- Attachment #3: bug.scm --]
[-- Type: text/plain, Size: 73 bytes --]

(use-modules (ice-9 format))
(define (hug x) (format #t "HUG ~a !\n" x))

[-- Attachment #4: Makefile --]
[-- Type: text/plain, Size: 97 bytes --]

CFLAGS += $(shell guile-config compile)
LDLIBS += $(shell guile-config link) -lpthread

all: bug

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

end of thread, other threads:[~2010-07-17 12:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-05  8:23 Thread and guile environment rixed
2010-07-05 19:52 ` Neil Jerram
2010-07-06 11:22   ` Cedric Cellier
2010-07-07 11:02     ` Cedric Cellier
2010-07-08 19:48 ` Andy Wingo
2010-07-09 15:54   ` Cedric Cellier
2010-07-09 19:10     ` Andy Wingo
2010-07-09 20:23   ` Neil Jerram
2010-07-10  8:22     ` Andy Wingo
2010-07-12 20:24       ` Linas Vepstas
2010-07-17 12:24         ` Andy Wingo
2010-07-12  8:09 ` Cedric Cellier

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).