The following a example image processing program coded by using the multithread facilities. Image input thread and filtering threads are created. samp-image takes image data periodically by waiting for samp-sem to be posted every 33msec. Two threads synchronize via read-and-write of a thread-port. Filter-image employs two more threads for parallel computation of filtering.
(make-threads 8) (defun samp-image (p) (let ((samp-sem (make-semaphore))) (periodic-sema-post 0.03 samp-sem) (loop (sema-wait samp-sem) (send p :write (read-image)))) (defun filter-image (p) (let (img) (loop (setf img (send p :read)) (plist (filter-up-half img) (filter-low-half img))))) (setf port (make-thread-port)) (setf sampler (thread #'samp-image port)) (setf filter (thread #'filter-image port))
k-okada 2013-05-21