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

Re: Threading/Process Question



Quoting Brent Fulgham:
> Must the new procedure be long-lived?

No.

> E.g., can it be something
> as trivial as (+ 1 2)?

Yes, the body of the procedure could be just "(+ 1 2)". But the thread
will terminate as soon as that expression is evaluated.

Which raises an interesting undocumented point --- calling
scheme_swap_thread on a terminated thread will crash.

In general, I recommend usesing scheme_process_block(0.0), and letting
the scheduler pick a thread, instead of swapping to a specific other
thread.

> I am actually making use of the exception-catching thunk code
> form the Inside MzScheme document.
> 
> In that code, I pass a text string that is my Scheme code to
> be evaluated:
> 
> value = _apply_thunk_catch_exceptions(scheme_make_closed_prim(do_eval,
>            (char*)cmd), &exn);
> 
> Which in turn calls evals internally:
> 
> v = _scheme_apply(exn_catchin_apply, 1, &f);
> 
> Where in this chain of calls is it best to do the thread switching?

You need to create the thread first, and in that thread go to the code
that sets up exception catching. The reason is that every thread has
its own exception handler.

> Could it be a simple as just passing MzScheme
> a dummy "(+ 1 2)" thunk earlier to create the thread, and leave
> the rest as-is?

A dummy thunk containing the body "(+ 1 2)" isn't going to help.
Whatever the thunk used to create the thread, it needs to eventually
set up exception catching and then evaluate the useful expressions that
you actually want to evaluate.

Matthew