You are not logged in.
I have been dabbling in common lisp for a few months now, to the point where it became a replacement for bash scripts (which I never really "got" into, anyway). After using ratpoison for quite a while I stumbled upon Stumpwm - a, so far, perfect window manager (language for which I already know, unlike xmonad).
After playing around with the rc file for a few weeks, I run into a minor problem. It is thus: is there a way to, without freezing the wm, make a function run, do something akin to 'sleep 1000', and then run again? Kinda like launching a bash script or something with 'sleep' in it, and adding "&" at the end, if that makes sense...
Oh, and I am using SBCL.
Last edited by countd (2011-06-28 21:24:45)
Offline
SBCL has its own implementation of thread. It's in the sb-thread package.
Example of printing "Hello, World!" to stdout every 10 seconds, forever:
(sb-thread:make-thread
(lambda ()
(loop do
(progn
(sleep 10)
(format t "Hello, World!~%")))))
But it's good practice to create a thread pool so you can terminate them or wait for them to finish when your program exits (i.e. when you quit stumpwm).
(use-package :sb-thread)
(defparameter *threads* '()) ; we stock all threads here
;; Helper to create and stock thread
(defun do-in-thread (fn)
(setf *threads*
(cons
(make-thread fn)
*threads*)))
;; Create some threads that loop forever
(do-in-thread
(lambda ()
(loop do
(progn
(sleep 3)
(format t "hello every 3sec~%")))))
(do-in-thread
(lambda ()
(loop do
(progn
(sleep 4)
(format t "Bye every 4sec~%")))))
;; Call this function when quiting stumpwm
(defun kill-all-threads ()
(loop for th in *threads*
do
(if (thread-alive-p th) (terminate-thread th))))
Last edited by jiyuu (2011-06-28 21:01:38)
Offline
Thank you! I guess I should have paid more attention to the docs =\
Offline