[plt-scheme] embedding: scheme_check_threads question

From: Dave Griffiths (dave at pawfal.org)
Date: Thu Apr 23 11:47:32 EDT 2009

On Wed, 2009-04-22 at 10:59 -0600, Matthew Flatt wrote:
> At Wed, 22 Apr 2009 17:37:51 +0100, Dave Griffiths wrote:
> > I've got a bit confused reading the docs on scheme_check_threads:
> > http://docs.plt-scheme.org/inside/threads.html#(part._threadtime)
> > 
> > I've noticed that plt threads running in fluxus tend to get starved in
> > an erratic fashion. The answer seems to be this function, but I'm a
> > little confused by the timer example, is the general idea to
> > periodically call it while threads are active? (using
> > scheme_notify_multithread).
> Yes.
> Since scheme_notify_multithread() isn't used by MrEd anymore, I worry
> that its support might have decayed. That is, it might not be called
> reliably when threads are ready to run. If you need it, you might try
> to double-check whether it works.
> Or you could just call scheme_check_threads() all the time, whether
> backgrounds threads are running or not. And that seems to be what
> you're doing, already...
> > I have a periodic update loop (the interpreter gets run once per frame)
> > so I've tried calling scheme_check_threads every update without much
> > luck, however, calling it 100 times in a loop every frame (!) seems to
> > fix my problem by giving enough time to the threads - but also causes
> > lockups in other situations. 
> > 
> > What am I missing?
> The scheme_check_threads() function performs a single round of thread
> swaps, and "round" depends on the structure of thread grups. If you
> have 100 active threads all in the same thread group, then it should
> let each of them run. If you have 100 threads in a nested thread group,
> though, it may take 100 calls for each thread within the group to get a
> chance to run. I think.
> How many other threads are there? do you create any thread groups?

In this case not that many (I'm not entirely sure), but they are needing
frequent updates as some of them are polling network sockets for stuff.

But in the general case, if the frequency/quantity of the
scheme_check_threads calls should dependant on the number of threads, is
there a way to find out and scale it appropriately?

Otherwise, I can just make it a user option which can be configured on
the scheme side.



Posted on the users mailing list.