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 system is similar to bordeaux-threads but has some unique features.

What I like is that portable-threads forces you to give the thread a name. No more Anonumous threads!

Also, there is a shortcut macro to start any code in a thread without wrapping it into an explicit lambda:

POFTHEDAY> (portable-threads:spawn-form 
             (format t "Running in ~S thread"

Running in "Form (FORMAT T ...)" thread
#<SB-THREAD:THREAD "Form (FORMAT T ...)" FINISHED values: NIL {10051E61C3}>

Or there is also a shortcut to run periodical tasks in the thread:

POFTHEDAY> (defun periodic ()
             (format t "[~A] Running in ~S thread~%"

POFTHEDAY> (portable-threads:spawn-periodic-function
            :count 3
            :verbose t)

;; Spawning periodic-function thread for...
#<SB-THREAD:THREAD "Periodic Function" RUNNING {100466CDB3}>
[2020-08-23T14:00:35.207071+03:00] Running in "Periodic Function" thread
[2020-08-23T14:00:40.214253+03:00] Running in "Periodic Function" thread
[2020-08-23T14:00:45.215454+03:00] Running in "Periodic Function" thread
;; Exiting periodic-function thread

Another cool feature not found in bordeaux-threads is thread hibernation. Any thread can fall asleep and be awakened later:

POFTHEDAY> (defun do-the-job ()
             (format t "Started a thread ~A~%"
             ;; Now we'll fall asleep until somebody will
             ;; call awake.
             (format t "Thread ~A works again!~%"

POFTHEDAY> (defparameter *thread*
             (portable-threads:spawn-thread "Worker"
Started a thread Worker

POFTHEDAY> (portable-threads:thread-whostate *thread*)

;; Now we wake thread up:

POFTHEDAY> (portable-threads:awaken-thread *thread*)
Thread Worker works again!

There are other interesting helpers like protected calls to work with lists.

Read the documentation to find more gems!

Brought to you by 40Ants under Creative Commons License