Each Lisp
mp:process
has a separate native thread. You can have many runnable
mp:process
objects/native threads, but Lisp code can only run in one thread at a time and a lock is used to enforce this. This can limit performance on multi-CPU machines.
When a foreign function is called using the FLI, the lock is released until the function returns. This allows other Lisp threads to run, for instance while waiting for a database query to execute.
You can call back into Lisp using
fli:define-foreign-callable
in any thread, without any other setup.
Note: In a LispWorks 5.0 executable on Microsoft Windows you must first call
setup-for-alien-threads
before calling back into Lisp, but in LispWorks 5.1 and later versions this setup is handled automatically (and
setup-for-alien-threads
does not exist).
Threads running Lisp code can be rescheduled preemptively, so if you call into Lisp from more than one thread simultaneously and one request takes a long time then it will not delay the requests in other threads.