[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Pushing events between C++ and Scheme + timers
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] Pushing events between C++ and Scheme + timers |
Date: |
Wed, 8 Dec 2004 21:21:19 +0100 |
On Wed, 8 Dec 2004 19:46:01 +0000, Joel Reymont <address@hidden> wrote:
> > felix winkelmann wrote:
>
> >Does the loop run continuously? You could call into Scheme periodically,
> >for example by checking timeouts for all suspended game states. If the
> >call into Scheme happens periodically, you could run a separate
> >(Scheme-level) background thread to check for this.
>
> Yes, the Scheme event-checking loop would run continuously and the C++
> loop would run continuously as well. When you say background Scheme-level
> thread you mean starting a thread in Scheme?
Indeed.
>
> >You can pass an incoming event as an s-expr to the Scheme side,
> >and receive the reply s-expr as a string as result, passing it back.
>
> That's what I want to store in the queues. Can these queues be simple
> Scheme lists?
Yes, or queues (see the manual - "extras" library unit).
>
> Could I implement timers by launching a separate Scheme thread and having
> it post an event to the "incoming" queue/list?
For example. Running multiple threads in code embedded in a C/C++
application is no problem, provided only one thread is called and returns
to the C side. If the other threads live completely in the Scheme world,
they will run happily in the background. But this requires that Scheme
is called every once in a while (which apears to be the case).
>
> I thought I could have 3 Scheme functions I would call from C++ where one
> would start the Scheme loop in a Scheme thread and the other two would
> let C++ post events (sexp) to the "incoming events" Scheme list and the
> other would retrieve them from the "outgoing" list. The post/retrieve
> functions would use a mutex to block access to the lists/queues. Then I
> could do the timer by launching another thread within Scheme.
>
> What am I missing?
>
I don't know. Looks good to me.
cheers,
felix