[plt-scheme] embedding: scheme_check_threads question

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Apr 22 12:59:05 EDT 2009

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?



Posted on the users mailing list.