RSS Feed

Lisp Project of the Day


You can support this project by donating at:

Donate using PatreonDonate using Liberapay

Or see the list of project sponsors.


Tests 😀
CI 🥺

This library contains a few primitives for parallel code execution. It is like a baby lparallel.

PCall provides a thread pool, few macro to execute and wait parallel task and a thread-safe Queue.

Here is a simple demo which runs two tasks in parallel and then executes a body. A digit on each line is a number of seconds elapsed since the form was evaluated:

POFTHEDAY> (let ((started-at (get-universal-time)))
             (flet ((info (message &rest args)
                      (let ((seconds-since-start
                              (- (get-universal-time)
                        (format t "~A: ~A~%"
                                (apply #'format nil message
               (pcall:plet ((foo (progn (info "Creating Foo")
                                        (sleep 5)
                                        (info "Foo was created")
                            (bar (progn (info "Creating Bar")
                                        (sleep 3)
                                        (info "Bar was created")
                 (info "Plet's body is executed immediately.")
                 (info "And it will wait for the result when you access the value.")
                 (info "Here is the Bar's value: ~S"
                 (info "Task foo still executing in the background.")
                 (info "Here is the Foo's value: ~S"
0: Plet's body is executed immediately.
0: And it will wait for the result when you access the value.
0: Creating Bar
0: Creating Foo
3: Bar was created
3: Here is the Bar's value: :BAR-RESULT
3: Task foo still executing in the background.
5: Foo was created
5: Here is the Foo's value: :FOO-RESULT

There are a few more interesting functions allowing to execute and wait for tasks. And a thread-safe queue can be loaded using the standalone system pcall-queue.

PCall can be useful when you don't need such a sophisticated tool as lparallel and just want to use thread pool or queue.

If you are interested in trying PCall, read it's docs here because it is not hosted on the GitHub and does not show it's docs either.

Brought to you by 40Ants under Creative Commons License