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

Re: Question on Multithreading from C API



Quoting Brent Fulgham:
> Looking at the "Inside PLT MzScheme" manual, I see how to
> create a new thread to evaluate the s-expression, but I
> don't see a way to join with an MzScheme thread to get
> it's response.

There's not one.

> For example, let's say I do this:
> 
> ... get a request ...
> 
> Scheme_Object* rval = scheme_thread( thunk, env);
> 
> ... return the rval ...
> 
> I imagine this is just going to block until the evaulation
> is done. 

No. It's going to return a thread-identifying value immediately,
regardless of what `thunk' computes.

> What I would like to do is have the request thread looping
> and periodically checking for new requests (which it does now),
> then hand them off to MzScheme to evaluate in their own
> threads, then periodically check on each thread to see if there
> was a result.

The technique you sketched is a good anything I could come up with.

One tricky part: While blocking on some C-based condition variable,
you'll want to allow MzScheme threads to run. See the "Threads in
Embedded MzScheme with Event Loops" section of _Inside PLT MzScheme_
for information on how to make this work.

Matthew