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

Re: Threading/Process Question



Quoting Brent Fulgham:
> What's the best way of starting up multiple interpreter threads
> that have relatively isolated namespaces?

Each thread normally has a separate copy of the `current-namespace'
parameter, so you can just set the parameter after creating the thread.

> My current stab at this looks something like this:
>
> [...]
> 
>     // This code is used to create a new thread that might
>     // be swapped to in the future.
>     Scheme_Process* proc = scheme_thread(NULL, config);

The main problem here is that NULL is not allowed as the first argument
to scheme_thread. It needs a procedure to start executing in the new
thread.

Also, you don't want to supply the "config" (a set of parameter values)
of the current thread to the created one, otherwise they'll share
parameter values.

Instead, create a new one:

  scheme_thread(thunk, scheme_make_config(scheme_config));

[Note: the docs claim that NULL is a legal second argument to
scheme_thread(), but it isn't anymore.]

>     ... Still later, I want to get back to thread "A"
>     scheme_swap_process(proc);
> 
> However, this doesn't work right -- it causes me to segfault
> when I try to execute code after the scheme_swap_process.

Actually, the segfault is within scheme_swap_process(), because it's
trying to jump to the NULL procedure, right?

> Does "scheme_thread" return a real, usable Scheme_Process*,

Yes, assuming that it gets valid procedure and config values.

Matthew