Chakravarthi Muralidar <[EMAIL PROTECTED]> writes:

> Is there some way to let linux /bsd do the scheduling work instead of
> (mp:process-yield)

What you're thinking of is preemptive threading where the underlying
threading system steps in to handle the thread switch rather than the
programmer having to specify the switching explicitly. In particular
you're asking for OS-level preemptive threading where the operating
system does the switching. CMUCL has no support for this, but it is
available in SBCL (a fork of CMUCL) on x86 systems.

Using MP:PROCESS-YIELD you could probably implement your own
preemptive threading system inside CMUCL but it would be a lot of work
that might be better spent on other tasks (like making preemptive OS
threads work in CMUCL).

In summary, there're two major threading models that exist,
cooperative threading and preemptive threading. In the former the
thread must itself hand control to some other thread. In the latter
the underlying threading system handles the change of control. The
threading system may be implemented in the operating system or in a
particular program. CMUCL has cooperative threads implemented in
CMUCL. SBCL provides preemptive threads implemented in the operating
system.

BTW, Unix OS processes are basically preemptive OS-level threads. When
you call fork() you get a copy of the current process (thread) which
retains the environment of the original until some part of the
environment is changed, at which point that part is copied into the
space of the new process (copy-on-write). The difference between
threads and processes is ostensibly that threads are lighter-weight
than processes, ie that switching threads is cheaper than switching
processes. Unix has very light-weight or low-overhead process
switching so the difference between threads and processes is
minimized.

> At what intervals of time should process-yield be called??

Whenever it's convenient for your program, and often enough to where
all your threads get to run equally.

> does it have an overhead?

All thread switching in single-processor situations has some overhead
since the processor must have its current context of the switched-from
thread saved and the one for the switched-to thread loaded. So yes, it
has overhead. Not a terribly large amount though.

'james

-- 
James A. Crippen <james at unlambda.com> Lambda Unlimited
61.2204N, -149.8964W                     Recursion 'R' Us
Anchorage, Alaska, USA, Earth            Y = \f.(\x.f(xx))(\x.f(xx))

Reply via email to