Re: more than one thread, no return to C (was: SQLite 2.4.7)
feeley at IRO.UMontreal.CA
Wed Jan 26 21:03:33 EST 2005
> Given the general case, that a Scheme procedure calls a C function
> which in turn calls another Scheme procedure: does it matter whether
> the inner (latter) Scheme procedure is a callback procedure (i.e.
> given by the caller of the outer Scheme procedure) or not? I don't
> think so. Is this then the general rule for avoiding the problem:
> don't nest Scheme procedure calls indirectly via C?
Whether it is a callback or not is immaterial. The important thing is
that you have a call from Scheme to C in which is nested a call from C
to Scheme. In such a situation the "continuation" contains C frames.
There is a risk that these C frames will be popped by an (unrelated)
call to a continuation that contains another C frame (that was pushed
on the C stack earlier). This might happen in a multithreaded program
if more than one thread does these Scheme -> C -> Scheme calls and the
scheduler interleaves the execution of the threads (because of
preemption, I/O blocking the threads, etc). When there are only
Scheme to C calls the issue does not arise.
More information about the Gambit-list