chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Repetitive callback into scheme from C thread hangs


From: felix winkelmann
Subject: Re: [Chicken-users] Repetitive callback into scheme from C thread hangs
Date: Wed, 23 Nov 2005 07:30:59 +0100

On 11/22/05, Matthew David Parker <address@hidden> wrote:
>
> Normally to do a callback I'd do this:
>
> (define call.foo
>         (foreign-safe-lambda void "callfoo"))
>
> (define AImain
>         (lambda ()
>                 (printf "hello\n")))
>
> (define foo
>         (foreign-safe-wrapper void "foo"
>                 () (lambda () (AImain))))

I highyly recommend using `define-external' instead
of `foreign-safe-wrapper', which is a bit error-prone
(it expects a lambda as its last argument, etc.)

>
> And then in my C code:
>
> void callfoo (void) {
>         foo();
> }
>
>
> I've tested this and it works well.  I can even redefine "AImain" and get
> it to do different things when I callback foo.
>
> For this game I'm working on, it runs in a thread and runs at about 16
> frames per second.  For every frame I want it to callback to an AI
> function in scheme.  However, when I implement the above into my game, the
> game hangs when it calls foo() and it doesn't actually do anything in the
> foo function.  I'm guessing this has something to do with it running from
> a thread?  Also, in the above example I call a C function from scheme that
> immediately calls back into scheme, though in my game I just set a
> variable that says it can start calling "foo", and when it actually calls
> foo is when it hangs.  I am hoping to do this without including
> "chicken.h" in my game library (to make it more versatile).  Is that even
> possible?
>

You don't need chicken.h, if you are just invoking callbacks.
You are using native threads, to run your game, right?
Is it possible that different threads call into Scheme code? The
runtime system is single-threaded and not reentrant.


cheers,
felix




reply via email to

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