Re: Thread and guile environment

2010-07-12 Thread Cedric Cellier
This works if I explicitely define a module _and_ export the hug symbol.

(define-module (bug))
(export hug)

(use-modules (ice-9 format))
(define (hug x) (format #t HUG ~a !\n x))
#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, ((@ (bug) hug) 2));
	return NULL;
}

int main(void) {
	scm_with_guile(load_file_with_guile, bug.scm);

	scm_with_guile(hug_me, ((@ (bug) hug) 1));

	pthread_t thread;
pthread_create(thread, NULL, thread_hugme, NULL);

	pthread_join(thread, NULL);

	return 0;
}


Re: Thread and guile environment

2010-07-12 Thread Linas Vepstas
Hi,

On 10 July 2010 03:22, Andy Wingo wi...@pobox.com wrote:
 Hi,

 On Fri 09 Jul 2010 22:23, Neil Jerram n...@ossau.uklinux.net writes:

 Andy Wingo wi...@pobox.com writes:

 Interestingly, the first thread has you in (guile-user), but the second
 has you in (guile). So you don't see the full definition of format, nor
 do you see hug.

 That's what I thought too.  But in that case I have no idea why my
 '(define-module (guile-user))' suggestion didn't work.

 I think bug.scm was loaded in the main module -- the threads just tried
 to call a function defined by bug.scm, and as they were in (guile), not
 (guile-user), there was the error

Yes, this sounds a lot like the bug I saw few years ago ...
.
 But it's quite ugly. Does anyone have any input as to what module should
 be current when a thread previously unknown to Guile enters Guile?

 Surely it has to be (guile-user), since that what the end of boot-9.scm
 moves into - and hence is well-established for the single thread case.

 Agreed. I just pushed the following patch, which fixes Cedric's case.

Thanks.

Is this for guile1.8.8 or for 2.0?

--linas



Re: Thread and guile environment

2010-07-09 Thread Andy Wingo
On Mon 05 Jul 2010 09:23, ri...@happyleptic.org writes:

 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
 ?

Interestingly, the first thread has you in (guile-user), but the second
has you in (guile). So you don't see the full definition of format, nor
do you see hug.

A workaround is to do:

scm_with_guile(hug_me, (begin (set-current-module (resolve-module 
'(guile-user))) (hug 2)));

instead of

scm_with_guile(hug_me, (hug 2));

But it's quite ugly. Does anyone have any input as to what module should
be current when a thread previously unknown to Guile enters Guile?

Andy
-- 
http://wingolog.org/



Re: Thread and guile environment

2010-07-09 Thread Cedric Cellier
-[ Thu, Jul 08, 2010 at 08:48:33PM +0100, Andy Wingo ]
 Interestingly, the first thread has you in (guile-user), but the second
 has you in (guile). So you don't see the full definition of format, nor
 do you see hug.

Interresting indeed.
Is there a definition of these modules and their purpose somewhere ?

   scm_with_guile(hug_me, (begin (set-current-module (resolve-module 
 '(guile-user))) (hug 2)));

Ok for me.
I think I will have to play with modules anyway (see my other thread).

Thank you for your help !




Re: Thread and guile environment

2010-07-09 Thread Andy Wingo
On Fri 09 Jul 2010 17:54, Cedric Cellier ri...@happyleptic.org writes:

 -[ Thu, Jul 08, 2010 at 08:48:33PM +0100, Andy Wingo ]
 Interestingly, the first thread has you in (guile-user), but the second
 has you in (guile). So you don't see the full definition of format, nor
 do you see hug.

 Interresting indeed.
 Is there a definition of these modules and their purpose somewhere ?

Mmm, some of this is not as documented as it should be. There is
Modules in the manual, and there is the source of boot-9.scm (fairly
well commented). If you have more specific questions, please ask the list.

Andy
-- 
http://wingolog.org/



Re: Thread and guile environment

2010-07-06 Thread Cedric Cellier
-[ Mon, Jul 05, 2010 at 08:52:44PM +0100, Neil Jerram ]
 ri...@happyleptic.org writes:
 Hm.  I think I recall a bug to do with different threads starting in
 different modules.  Does it work if you add

 (define-module (guile-user))

 at the start of your bug.scm ?

Same behavior :

ERROR: Unbound variable: hug

Nobody's doing something similar ?





Thread and guile environment

2010-07-05 Thread rixed
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


Re: Thread and guile environment

2010-07-05 Thread Neil Jerram
ri...@happyleptic.org writes:

 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 ?

Hm.  I think I recall a bug to do with different threads starting in
different modules.  Does it work if you add

(define-module (guile-user))

at the start of your bug.scm ?

 Neil