This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Using Guile with threads



All access to the guile interpreter must live in just one thread.  The
way to emulate multiple threads accessing the interpreter at the same
time is to use a 'guile-interpreter' thread that takes computation
requests off a mutex protected queue, and then signals the condition
variable associated with the request.

Pseudo code of guile thread:

* wait for data on input queue.
* process computation request.
* store result into request structure.
* signal condition variable on request structure.
* top.

Pseudo code of other thread:

* create request structure, with condition variable to wait on until
  result is ready.
* put request structure onto input queue.
* signal guile thread that data is there
* wait on request condition variable.

You can have multiple threads putting data into the input queue, thus
emulating the desired behavior.  I agree that it's too bad that guile
doesn't have real thread support :-(  

I have some code which (not in working order) based on the above
ideas, which I wanted to put into the FAQ, but I haven't gotten to
it. I'll send it to you if you want.  I hope this helps,

-russ


"Frederic Brunel" <brunel@mail.dotcom.fr> writes:

> First of all, I'm trying to use Guile in a small C++
> 3D engine. All I want is to launch a console 
> (like the scrip-fu console of Gimp) in a thread and
> an OpenGL session in another.
> The two threads must have access to Guile. The 
> console thread will evaluate scheme code to build 
> new objects and put them in the 3D world (in real-time) 
> and the other thread is the world main loop, its
> job is to update all 3D objects by calling scheme
> code to control them.

--
If I haven't seen further, it is by standing in the footsteps of giants.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]